问题描述:

Okay, I know there are similar post to this. But all I can see is they are using DATETIME() data type, mine is TIME() only.

I manage to store time using mysql time(now()). The format it stored is in 24hours format.

When I retrieve its value to some label in VB.NET I need to display it in 12 hours format. What I have done so far is the code below. but no luck.

 dataSet = New DataSet

adapter.SelectCommand.CommandText = "SELECT timein_pm from dtr WHERE cats_id='" & Trim(lblId.Text) & "'"

adapter.Fill(dataSet)

Label6.Text = dataSet.Tables(0).Rows(0)("timein_pm").ToString("hh:mm tt")

How do I do it? Also is it possible to do it via mySQL time format or something?

EDITED:

Database Values:

id date timein_pm id

57 2013-12-04 15:24:13 0828

网友答案:

If you need a MySQL solution you can use TIME_FORMAT() function

SELECT TIME_FORMAT(timeout_pm, '%h:%i:%s %p') time_12h
  FROM dtr
 WHERE ...

Here is SQLFiddle demo

网友答案:
DateTime dateTime = DateTime.Now;
string strMinFormat = dateTime.ToString("hh:mm:ss tt");//12 hours format

try this....

相关阅读:
Top