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
Old Hand
Old Hand (394 reputation)Old Hand (394 reputation)Old Hand (394 reputation)Old Hand (394 reputation)Old Hand (394 reputation)Old Hand (394 reputation)Old Hand (394 reputation)Old Hand (394 reputation)

Group: General Forum Members
Points: 394 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
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3940 Visits: 1623
select convert(varchar,getdate(),111)

Regards,
Raj

http://Strictlysql.blogspot.com
vaibhav.tiwari
vaibhav.tiwari
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1048 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
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1572 Visits: 3510

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
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1048 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
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22039 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
Right there with Babe
Right there with Babe (725 reputation)Right there with Babe (725 reputation)Right there with Babe (725 reputation)Right there with Babe (725 reputation)Right there with Babe (725 reputation)Right there with Babe (725 reputation)Right there with Babe (725 reputation)Right there with Babe (725 reputation)

Group: General Forum Members
Points: 725 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 Guru
SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)

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

SELECT {fn CURRENT_DATE()};





Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
richellere
richellere
SSC Eights!
SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)

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

Group: General Forum Members
Points: 79256 Visits: 11400
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