forsters
asked on
MS SQL - GETDATE() WHERE DATEPART(m, GETDATE())
Hi Experts,
Quick one, is there a simple way to get the dates of the current month and or week using GETDATE() and datepart as suggested by my title?
So to be clear I don't want the week number or month number but the dates that make up the current week or month...is this possible does anyone know??
Many thanks in advance
Quick one, is there a simple way to get the dates of the current month and or week using GETDATE() and datepart as suggested by my title?
So to be clear I don't want the week number or month number but the dates that make up the current week or month...is this possible does anyone know??
Many thanks in advance
If you mean just return the day, i.e. 7-12-2013 returns 12..
SELECT DATEPART(d, GETDATE())
SELECT DATEPART(d, GETDATE())
ASKER
Hi Thanks for your comments, no what I mean is GETDATE() i.e. 12/07/2013 - thats the format I want but I want to retrieve the array of dates that comprise this week e.g. 08/07/2013, 09/07/2013, 10/07/2013, 11/07/2013, 12/07/2013, 13/07/2013, 14/07/2013....is there a way to do that do you know?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
@angelIII: VERY IMPRESSIVE!!! I would vote for your solution!
ASKER
Wow! thank you both, amazing, I thought I was on a no-hoper with this but that is just brilliant, thanks so much.
Please note that my solution needs to be corrected.
Change: WHERE DATEADD(day, 1, EndValue) < @endDate
to this: WHERE EndValue <= @endDate
Change: WHERE DATEADD(day, 1, EndValue) < @endDate
to this: WHERE EndValue <= @endDate
ASKER
Oh? But it worked...
I found that the original query I posted showed only dates up to 2 days before the end of the period (in that case 29 rather than 31).
ASKER
Oh yeh I see, I'm missing a day - now fixed perfect
What do you mean by this ... Monday, Tuesday, Wednesday?
On most servers, 1=Sunday and 7=Saturday. Check that yours hasn't been altered.
SELECT DATEPART(DW, GETDATE())