Convert date / time to simple time

I have a field that expresses time as:

1900-01-01 07: 00: 00.000

But I would like to convert it just at 07:00. The closest I can find is:

Convert(Varchar(20), DT.EarlyShiftStart, 114) 

This gives me:

10: 30: 00: 000

But I would like to reset milliseconds and add AM / PM. Does anyone know the correct meaning?

0
datetime sql-server-2008
source share
1 answer

Data and data mapping are best separated. This makes it easy to customize what the user sees, without delving into the interior of programming. For example, if you used datetimes database data as strings, then it would be more difficult to display these dates in different formats - if you wanted to display them in local time, then you would need to convert it back to time, adjusted, and then converted back to string. If you threw away the date information by deleting it at the database level, this may not be possible. Even a change from 12 to 24 hour format would be difficult.

Since the data will (probably) be used in SSRS, it is better to use the formatting capabilities present in it. For example, you could do what you want with something in the lines

 =Format(yourTime, "hh:mm tt") 

in SSRS. Then, if you want to show 24-hour time in one part of the report, it will just be using something like

 =Format(yourTime, "HH:mm") 

and elsewhere in a report that needs 12 hours, it can remain as it is.

+1
source share

All Articles