Tuesday, September 20, 2011

Get Hour:Minute Format from DATETIME data type in SQL Server 2008


I found a problem when i want to display TIME data in hour:minute format. When i display TIME data types, the result is hour:minute:second : milisecond. The display is very annoying for me.
After doing some experiment, i have solve the problem in a simple way. To get the hour:minute format, you only have to convert the TIME data to VARCHAR(5). And the format is automatically changed to hour:minute format.
ex :
SELECT s.Days,CONVERT(VARCHAR(5),s.Hour) AS Hour
And the result will be like this :


Hopefully this post will solve your problem... ^_^

2 comments:

  1. Kak Steve..
    aku anak 2010 yg tadi minta bantuan.
    aku disuruh buat program yg ada messagebox.
    ada nilai, grade, ipk

    grade, ipk itu keluar setelah button di klik...

    nilai yg udah dimasukin, kalo bisa masuk tabel, atau database...ada tabel khusus history untuk nilai yg udah diproses


    mohon bantuan sebisanya aja kak...
    terimakasih banyakkk kak

    ReplyDelete
  2. Kalau seperti yang ditugasin ya bisa2 aja.. Cuma kurang sip kalau km kukasih langsung jadi.. Itu di post terbaru udah q bikinin cara akses Stored Procedure.. Coba pahamin.. Itu aja udah cukup buat bikin program seperti yang ditugasin.. Contohnya di Console Application.. Tinggal km ubah ke Windows Form aja.. Code-nya sama persis kok.. Tinggal pengaturannya.. Semangat ya.. ^_^

    ReplyDelete