September 8, 2015 at 7:45 am
Hello
I have a query where:
WHERE a.jobdate >=GETDATE()-1
This brings though data from today and yesterday; I understand this is because GETDATE = now.
However, all I want is to see is data from today only.
Is there any way the above query can be amended - probably not using GETDATE - so I can achieve this?
Many thanks for any advice.
September 8, 2015 at 7:49 am
faulknerwilliam2 (9/8/2015)
HelloI have a query where:
WHERE a.jobdate >=GETDATE()-1
This brings though data from today and yesterday; I understand this is because GETDATE = now.
However, all I want is to see is data from today only.
Is there any way the above query can be amended - probably not using GETDATE - so I can achieve this?
Many thanks for any advice.
Yeah this is pretty simple. You can do this a couple ways.
Here is one way. This is based on the excellent examples from Lynn found here. http://www.sqlservercentral.com/blogs/lynnpettis/2009/03/25/some-common-date-routines/%5B/url%5D
WHERE a.jobdate > dateadd(day, datediff(day, 0, GETDATE()), 0)
You can also simplify this a bit and just cast getdate() as date like this.
WHERE a.jobdate > CAST(getdate() as date)
_______________________________________________________________
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 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply