January 23, 2012 at 2:09 pm
Hi there, I am looking for a function that will return today's date without the time. Date() does this in Access, what is the equivalent of date() in SQL Server? Thanks
January 23, 2012 at 2:20 pm
Try this...
SELECT CAST(CAST(GETDATE() AS DATE) AS DATETIME)
This will 0 out the date. If you want the actual date only, then just do this:
SELECT CAST(GETDATE() AS DATE)
NOTE: This will not work on 2005
Jared
CE - Microsoft
January 23, 2012 at 2:20 pm
SELECT CONVERT(DATE, CURRENT_TIMESTAMP)
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
January 23, 2012 at 2:23 pm
Or just use the date datatype.
declare @MyDate date = CURRENT_TIMESTAMP
select @MyDate
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 23, 2012 at 2:29 pm
or the following
declare @Date date = GETDATE()
select @Date
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
January 23, 2012 at 4:17 pm
Is there a way to get the numeric value of the date only (with 0:00 time) and use it in a subtraction?
This is what I have right now, but I get the error "Explicit conversion from data type date to numeric is not allowed."
(CONVERT(numeric, CONVERT(date, current_timestamp), 101))-(CONVERT(numeric, abb.[due date], 101))
January 23, 2012 at 4:39 pm
Why don't you use the DATEDIFF() function?
What's the goal you're trying to achieve?
January 23, 2012 at 4:39 pm
What is your end goal?
What should the data look like after performing this calculation?
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
January 23, 2012 at 4:41 pm
LutzM (1/23/2012)
Why don't you use the DATEDIFF() function?What's the goal you're trying to achieve?
That is funny - same question (goal), same time - different sources.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
January 23, 2012 at 4:48 pm
SQLRNNR (1/23/2012)
LutzM (1/23/2012)
Why don't you use the DATEDIFF() function?What's the goal you're trying to achieve?
That is funny - same question (goal), same time - different sources.
If I wouldn't be involved, I'd say something along "Great minds think alike"...
But now all I can say about my post is "Every dog has its day." 😀
January 23, 2012 at 4:51 pm
LutzM (1/23/2012)
SQLRNNR (1/23/2012)
LutzM (1/23/2012)
Why don't you use the DATEDIFF() function?What's the goal you're trying to achieve?
That is funny - same question (goal), same time - different sources.
If I wouldn't be involved, I'd say something along "Great minds think alike"...
But now all I can say about my post is "Every dog has its day." 😀
Looks like my day was today. 😉
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
January 24, 2012 at 7:40 am
I am looking to get an integer (the number of days between the 2 dates)
January 24, 2012 at 7:42 am
Just use datediff for that. http://msdn.microsoft.com/en-us/library/ms189794.aspx
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply