Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting date in SQL to shortdate

Status
Not open for further replies.

cheryl27284

Technical User
Jan 31, 2003
28
0
0
US
Here is an easy question for you pros. I was unable to find this anywhere. I need to convert a date that looks like this: oct 16 2005 10:35PM into this 22:35.. What is the function to convert to shortdate?
 
Copy/paste this in to a query analyzer window to see how it works.

Code:
Declare @Temp VarChar(100)
Set @Temp = 'oct 16 2005 10:35PM'

Select Convert(VarChar(5), Convert(DateTime, @Temp), 108)



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
If you look up Convert in BOL you will see a table of conversion codes for the style parameter (which will explain what the 108 in gmmastros' solution does).

Hope this helps.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top