Date Format Problem | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Date Format Problem

When i run this (query1)
declare @date datetime
select top 1 @date=vehicle_gpsdatetime
from vehicle_history
select @date
i get the output
2004-05-31 10:10:58.000
this is the value stored in table but when i use print instead of select (in last line )
i get the output
May 31 2004 10:10AM
i didn’t understand this behavior Thanks
To be honest, you should use the PRINT statement only for debugging purposes, or in ad-hoc scripts. It can even cause problems in production systems, so remove them from code once you’re done debugging.
start by looking in books online -> CONVERT
to see the varius date time format options
Print date will convert it into varchar datatype. It is equivalent to Select convert(varchar,date,100)
Madhivanan Failing to plan is Planning to fail
As per Mr. Madhivanan’s suggestion using print will convert the date data type to varchar data type, Which is correct. if you need the print with SQL statement , please use different style formats with CONVERT function for your required results, which is as below: select …..,convert(varchar,your date field,20) from <your table> varchar – date will converted to
20 – style what i think you require.
You can try other styles like 1,2,3,4,100,etc B.K. Das
Apart from the different format, are you just curious why there are different formats or is this a problem for you? —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs

I think it is just for curiosity [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br />Madhivanan<br /><br />Failing to plan is Planning to fail
It is just for curiosity
Thanks
]]>