Click here to monitor SSC
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 Journeyman
SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)

Group: General Forum Members
Points: 76 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
Mr or Mrs. 500
Mr or Mrs. 500 (558 reputation)Mr or Mrs. 500 (558 reputation)Mr or Mrs. 500 (558 reputation)Mr or Mrs. 500 (558 reputation)Mr or Mrs. 500 (558 reputation)Mr or Mrs. 500 (558 reputation)Mr or Mrs. 500 (558 reputation)Mr or Mrs. 500 (558 reputation)

Group: General Forum Members
Points: 558 Visits: 1588
select convert(varchar,getdate(),111)

Regards,
Raj

http://Strictlysql.blogspot.com
vaibhav.tiwari
vaibhav.tiwari
SSC Journeyman
SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)

Group: General Forum Members
Points: 88 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
Mr or Mrs. 500
Mr or Mrs. 500 (510 reputation)Mr or Mrs. 500 (510 reputation)Mr or Mrs. 500 (510 reputation)Mr or Mrs. 500 (510 reputation)Mr or Mrs. 500 (510 reputation)Mr or Mrs. 500 (510 reputation)Mr or Mrs. 500 (510 reputation)Mr or Mrs. 500 (510 reputation)

Group: General Forum Members
Points: 510 Visits: 3384

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
SSC Journeyman
SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)

Group: General Forum Members
Points: 88 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
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2469 Visits: 3431
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
SSC Journeyman
SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)

Group: General Forum Members
Points: 75 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
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

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

SELECT {fn CURRENT_DATE()};





Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
richellere
richellere
Say Hey Kid
Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)

Group: General Forum Members
Points: 712 Visits: 108
select cast(getdate() as date) doesn't work on SQL Server 2005
Paul White
Paul White
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10338 Visits: 11350
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