SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Get Date only from getdate() function


Get Date only from getdate() function

Author
Message
forum member
forum member
SSC-Enthusiastic
SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)

Group: General Forum Members
Points: 170 Visits: 906
Hi

I am using sql server 2005 and i would like reterive date only from the GetDate(). Please let me know how can i do this

For example: 2010-03-25 13:55:43.547

the required is only should be 2010-03-25

Please suggest

Thanks
arr.nagaraj
arr.nagaraj
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1894 Visits: 1595
select convert(varchar,getdate(),111)

Regards,
Raj

http://Strictlysql.blogspot.com
vaibhav.tiwari
vaibhav.tiwari
Mr or Mrs. 500
Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)

Group: General Forum Members
Points: 522 Visits: 334
As per required output -


select REPLACE( convert(varchar,getdate(),111), '/', '-')



Vaibhav K Tiwari
To walk fast walk alone
To walk far walk together
Dohsan
Dohsan
SSC Eights!
SSC Eights! (956 reputation)SSC Eights! (956 reputation)SSC Eights! (956 reputation)SSC Eights! (956 reputation)SSC Eights! (956 reputation)SSC Eights! (956 reputation)SSC Eights! (956 reputation)SSC Eights! (956 reputation)

Group: General Forum Members
Points: 956 Visits: 3485

SELECT CONVERT(VARCHAR(10), GETDATE(), 120) AS DT



If you do a quick search you should be able to find a few sites with lists of the different date formats using CONVERT.

Have a quick look over: http://www.sql-server-helper.com/tips/date-formats.aspx
vaibhav.tiwari
vaibhav.tiwari
Mr or Mrs. 500
Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)Mr or Mrs. 500 (522 reputation)

Group: General Forum Members
Points: 522 Visits: 334
Dohsan (3/31/2010)

SELECT CONVERT(VARCHAR(10), GETDATE(), 120) AS DT



If you do a quick search you should be able to find a few sites with lists of the different date formats using CONVERT.

Have a quick look over: http://www.sql-server-helper.com/tips/date-formats.aspx


Thanks for this information.

Vaibhav K Tiwari
To walk fast walk alone
To walk far walk together
SwePeso
SwePeso
SSCrazy Eights
SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)

Group: General Forum Members
Points: 9875 Visits: 3433
Also asked here
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/d12f8277-d921-4c92-9f03-a7019678cd7e

I answered
SELECT CAST(GETDATE() AS DATE)


N 56°04'39.16"
E 12°55'05.25"
brosspaxedi
brosspaxedi
Old Hand
Old Hand (315 reputation)Old Hand (315 reputation)Old Hand (315 reputation)Old Hand (315 reputation)Old Hand (315 reputation)Old Hand (315 reputation)Old Hand (315 reputation)Old Hand (315 reputation)

Group: General Forum Members
Points: 315 Visits: 261
If I'm not mistaken, SELECT CAST(GETDATE() AS DATE) will only work on SS2008 and above, as the DATE type is new in 2008.

*******************
What I lack in youth, I make up for in immaturity!
Paul White
Paul White
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: General Forum Members
Points: 36494 Visits: 11361
If there are points available for being obscure...

SELECT {fn CURRENT_DATE()};





Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
richellere
richellere
Right there with Babe
Right there with Babe (762 reputation)Right there with Babe (762 reputation)Right there with Babe (762 reputation)Right there with Babe (762 reputation)Right there with Babe (762 reputation)Right there with Babe (762 reputation)Right there with Babe (762 reputation)Right there with Babe (762 reputation)

Group: General Forum Members
Points: 762 Visits: 108
select cast(getdate() as date) doesn't work on SQL Server 2005
Paul White
Paul White
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: General Forum Members
Points: 36494 Visits: 11361
richellere (4/3/2010)
select cast(getdate() as date) doesn't work on SQL Server 2005

Bross mentioned that. :-)



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search