nixxrite
nixxrite

Reputation: 125

DateDiff Sql query excluding weekends as vairable using variable to create > X

I have a bit of an issue, I've looked at other questions around this and notably seen this similar issue.

However mine is that I'm writing a SQL query within PHP to pull data from an access database to display via the browser.

My query starts Select, a, b, c etc and then I get to the problem. One of my select criteria is

DATEDIFF('d',[Activity].[CreatedOn], NOW()) as Dif 

Which works fine and pulls the number of days between created and now. However, if I add.

DATEDIFF('d',[Activity].[CreatedOn], NOW())- (DATEDIFF('wk', [Activity].[CreatedOn], NOW()) * 2) As Dif

Then the query returns nothing. In theory I should see the number of days minus number of weeks *2 to give me a rough idea of working days.

the second issue is trying to use my Dif variable to only show results where

Dif >= 7. 

I assume this is due to how the actual value in the field is displayed as oppose to the output I have which is a numerical digit.

Appreciate any pointers where I'm going wrong with this.

FIXED second issue

AND (Activity.CreatedOn < NOW()-7)

Upvotes: 0

Views: 50

Answers (1)

Andre
Andre

Reputation: 27634

The DateDiff parameter interval for week is 'ww', not 'wk'.

Upvotes: 1

Related Questions