Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Selecting the time

Author  Topic 

mark1504
Posting Yak Master

103 Posts

Posted - 2005-04-12 : 09:11:28
Is this the best method of selecting the time from a date field?

(The lower case is my display preference.)

SELECT LOWER(SUBSTRING(Convert(varchar(19),GETDATE(),100),13,7))

Thanks
Mark

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-04-12 : 09:17:41
Try this
SELECT Convert(varchar(20),GETDATE(),108)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

mark1504
Posting Yak Master

103 Posts

Posted - 2005-04-12 : 09:20:30
Sorry, the output from my example is the one I require: i.e. 2:20pm
Go to Top of Page

AndyB13
Aged Yak Warrior

583 Posts

Posted - 2005-04-12 : 09:26:22
Or you could use

SELECT LOWER(RIGHT(Convert(varchar(19),GETDATE(),100),7))

Andy

Beauty is in the eyes of the beerholder
Go to Top of Page

mark1504
Posting Yak Master

103 Posts

Posted - 2005-04-12 : 09:46:17
Thanks Andy. Doesn't look like there's much to choose from these, although yours is a few characters shorter, and that always wins points in my book.

Should I assume that this is about as good as it'll get?

Regards
Mark
Go to Top of Page
   

- Advertisement -