Pick time out of datetime

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
 
G

Gregory A. Beamer

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! |
*******************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top