Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

Get Date only from getdate() function Expand / Collapse
Author
Message
Posted Tuesday, March 30, 2010 8:58 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, September 1, 2011 10:58 AM
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
Post #893452
Posted Tuesday, March 30, 2010 9:31 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Sunday, August 24, 2014 11:58 PM
Points: 488, Visits: 1,338
select convert(varchar,getdate(),111)

Regards,
Raj

Strictlysql.blogspot.com
Post #893456
Posted Wednesday, March 31, 2010 1:57 AM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, July 27, 2012 11:13 AM
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
Post #893531
Posted Wednesday, March 31, 2010 2:38 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, August 22, 2014 2:10 AM
Points: 354, Visits: 2,567
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
Post #893545
Posted Wednesday, March 31, 2010 3:04 AM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, July 27, 2012 11:13 AM
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
Post #893562
Posted Wednesday, March 31, 2010 4:34 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, August 26, 2014 12:48 PM
Points: 2,397, Visits: 3,406
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"
Post #893611
Posted Thursday, April 1, 2010 7:08 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, August 22, 2014 11:30 AM
Points: 67, Visits: 219
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!
Post #894712
Posted Thursday, April 1, 2010 8:22 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Monday, August 25, 2014 6:32 PM
Points: 11,194, Visits: 11,140
If there are points available for being obscure...
SELECT  {fn CURRENT_DATE()};





Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #894822
Posted Saturday, April 3, 2010 7:16 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Wednesday, November 28, 2012 5:07 AM
Points: 712, Visits: 104
select cast(getdate() as date) doesn't work on SQL Server 2005
Post #896231
Posted Saturday, April 3, 2010 7:25 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Monday, August 25, 2014 6:32 PM
Points: 11,194, Visits: 11,140
richellere (4/3/2010)
select cast(getdate() as date) doesn't work on SQL Server 2005

Bross mentioned that.




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #896235
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse