user761758 user761758 - 1 year ago 266
SQL Question

t-sql convert datetime to time only with NO SECONDS

There are many t-sql CONVERT strings to produce quite a variety of date and or time strings. But I cannot find the solution to needing no date and no seconds.

We want to return the time only from a datetime field, and eliminate the seconds. It would not matter if the seconds were truncated or rounded, but we need to show no seconds.

desired results- from any DATETIME field
10:00 AM
11:00 AM
4:59 PM

any and all insights or suggestions appreciated!!

Answer Source

Would this do it?

select CONVERT(varchar(15),CAST(GETDATE() AS TIME),100)

Just change out GETDATE() with your date variable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download