Pick time out of datetime

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

I have a datetime field on SQL 2000 server db that I would like to pull out
a time for display separate from the date in a FormView. For example, I
have a datetime of '2009-07-30 15:00:00.000' and would like to come out with
the value '03:00 PM'. Thanks.

David
 
I have a datetime field on SQL 2000 server db that I would like to
pull out a time for display separate from the date in a FormView. For
example, I have a datetime of '2009-07-30 15:00:00.000' and would like
to come out with the value '03:00 PM'. Thanks.

To get time only, try:

select convert(varchar, getdate(), 8)

This will give you a 24 hour clock, which you can easily convert. It
also gives you the seconds, so it might not be your primary option


In .NET, you can use the ToShortTimeString() to get:

3:00 PM

Or ToLongTimeString() if you want seconds

3:00:15 PM


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top