Tuesday, March 27, 2012

getting the date

hey all,
when i use the GetDate() function it puts the time in there as well: how do
i get just the date?
thanks,
ariTry select convert(char(10),getdate(),101)
HTH,
Srinivas Sampangi
"ari" <ari@.discussions.microsoft.com> wrote in message
news:93DA4FC3-6F9E-455F-8D9E-D9E392EA6B15@.microsoft.com...
> hey all,
> when i use the GetDate() function it puts the time in there as well: how
> do
> i get just the date?
> thanks,
> ari|||On Sat, 15 Oct 2005 07:43:01 -0700, ari wrote:

>hey all,
>when i use the GetDate() function it puts the time in there as well: how do
>i get just the date?
>thanks,
>ari
Hi ari,
To get the date without time in datetime format (i.e. the time is set to
midnight, since you can't really _remove_ the time from a datetime), use
SELECT DATEADD(day,
DATEDIFF(day, '20050101', CURRENT_TIMESTAMP),
'20050101')
(You can replace '20050101' with any valid date, but make sure to
replacec it in both places).
To get the date without time in character format, use
SELECT CONVERT(char(8), CURRENT_TIMESTAMP, 112)
The style parameter 112 results in the ANSI standard date format
yyyymmdd. You can get other formats as well (check out the item on "CAST
and CONVERT" in Books Online for a full list), but they are less safe in
globally operating systems.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Impossible, if you want to have it as datetime. See
http://www.karaszi.com/SQLServer/info_datetime.asp for more info and recomme
ndations.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"ari" <ari@.discussions.microsoft.com> wrote in message
news:93DA4FC3-6F9E-455F-8D9E-D9E392EA6B15@.microsoft.com...
> hey all,
> when i use the GetDate() function it puts the time in there as well: how d
o
> i get just the date?
> thanks,
> ari|||date and time in SQL SERVER ARE SIAMY TWINS, You can't separate them. But yo
u
can view it whatever format you want.
Regards
R.D
--Knowledge gets doubled when shared
"Tibor Karaszi" wrote:

> Impossible, if you want to have it as datetime. See
> http://www.karaszi.com/SQLServer/info_datetime.asp for more info and recom
mendations.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "ari" <ari@.discussions.microsoft.com> wrote in message
> news:93DA4FC3-6F9E-455F-8D9E-D9E392EA6B15@.microsoft.com...
>

No comments:

Post a Comment