Home All Groups Group Topic Archive Search About
Author
8 Jul 2005 8:09 PM
qjlee
when i execute an query on date, the date in the result come up with
"2005-06-21 00:00:00:000"  what function I should use to elimate the 0s and
make it comes out as only "2005-06-21"
Thanks,

Author
8 Jul 2005 8:12 PM
Aaron Bertrand [SQL Server MVP]
SELECT CONVERT(CHAR(10), GETDATE(), 120)

However, this is no longer a DATETIME value, it is just a string.  Usually,
date formatting is better handled by the client / presentation tier, not the
query.



Show quote
"qjlee" <qj***@discussions.microsoft.com> wrote in message
news:32DB6687-36E3-4351-983B-E318664D25A1@microsoft.com...
> when i execute an query on date, the date in the result come up with
> "2005-06-21 00:00:00:000"  what function I should use to elimate the 0s
> and
> make it comes out as only "2005-06-21"
> Thanks,
Author
8 Jul 2005 8:14 PM
Stu
Look up CAST and CONVERT in the SQL Server Books OnLine.  Basically,
you'll need to convert the date value to a char or varchar.

HTH,
Stu
Author
8 Jul 2005 8:18 PM
Ravi
Refer CONVERT function in BOL

E.g

SELECT GETDATE() AS SystemDate,CONVERT(varchar,GETDATE(),101) AS FormattedDate

SystemDate                                             FormattedDate        

------------------------------------------------------
------------------------------
2005-07-08 16:07:37.310                                07/08/2005

(1 row(s) affected)

(1 row(s) affected)

will give you


--
Thanks & Rate the Postings.
-Ravi-


Show quote
"qjlee" wrote:

> when i execute an query on date, the date in the result come up with
> "2005-06-21 00:00:00:000"  what function I should use to elimate the 0s and
> make it comes out as only "2005-06-21"
> Thanks,
Author
8 Jul 2005 9:48 PM
njdevore
Hello qjlee,

Are you wanting to format it different because you can't do so in your front
end app?

At any rate, if you can convert it to a string, then you can use

convert(char(10),yourDateColumn,101)

....which will give you the date in MM/DD/YYYY, which is not exactly what
you want, but close.  Otherwise, you can use the datepart function to get
each part.

-Nick

Show quote
> when i execute an query on date, the date in the result come up with
> "2005-06-21 00:00:00:000"  what function I should use to elimate the
> 0s and
> make it comes out as only "2005-06-21"
> Thanks,

AddThis Social Bookmark Button