Thursday, March 22, 2012

datetime transformation

Hello,
How can I convert datetime value :
2005-10-11 00:00:00.000
to date value:
2005-10-11 ?
Thanks,
GBSee CONVERT() function in SQL Server Books Online.
Anith|||On Thu, 11 May 2006 20:46:39 GMT, GB wrote:

>Hello,
>How can I convert datetime value :
>2005-10-11 00:00:00.000
>to date value:
>2005-10-11 ?
Hi GB,
Technically, these are the same values. If a datetime is given without
time portion, it defaults to midnight. So no conversion needed.
If your question is about showing the date only and suppressing the time
part, my first recommendation would be to do the formatting in the
front-end. This has the advantage that you can take the locale settings
of the workstation into account and format the date the way the
individual user prefers.
If you HAVE to do it on the server, then check out the subject on CAST
and CONVERT in Books Online. Adjusting the style parameter allows you to
convert a datetime to a string variable with the foormatting of your
choice.
For instance, for yyyy-mm-dd, you could use
SELECT CONVERT(char(10), TheDate, 126)
Hugo Kornelis, SQL Server MVP

No comments:

Post a Comment