May 9, 2016 at 8:11 am
what Workday number is today in the month today is may 9th but the workday number is 6
I need away to get the workday number using getdate()
May 9, 2016 at 8:25 am
kat35601 (5/9/2016)
what Workday number is today in the month today is may 9th but the workday number is 6I need away to get the workday number using getdate()
what code are you using to get "workday" ?
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
May 9, 2016 at 8:30 am
That is what I am looking for I need to be able to get what workday number the current day is saturday and sunday would be 0
May 9, 2016 at 8:40 am
one way is...Gooogle for others....this doesnt auto magically know about your own national holidays / work holidays ....yadda yadda
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = '20160501'
SET @EndDate = GETDATE()
SELECT
(DATEDIFF(dd, @StartDate, @EndDate) + 1)
-(DATEDIFF(wk, @StartDate, @EndDate) * 2)
-(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
-(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
May 9, 2016 at 8:46 am
Thank you I change it a little but get the same results
SELECT
(DATEDIFF(dd,DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0), getdate()) + 1)
-(DATEDIFF(wk, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0), getdate()) * 2)
-(CASE WHEN DATENAME(dw, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0)) = 'Sunday' THEN 1 ELSE 0 END)
-(CASE WHEN DATENAME(dw, GETDATE()) = 'Saturday' THEN 1 ELSE 0 END)
does that look ok it seems to work fine.
Thanks again
May 9, 2016 at 10:30 am
You'll be missing any holidays. To prevent that, you'll need to create a calendar table or at least a holidays table.
May 9, 2016 at 11:03 am
Luis Cazares (5/9/2016)
You'll be missing any holidays. To prevent that, you'll need to create a calendar table or at least a holidays table.
I normally use the Dim_Date table from the Data Warehouse for things like this. Check, you might already have a good starting point.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply