Dates this quarter

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Dates this quarter

Post by D Willett »

Hi.
The following query returns dates >=155.
What I would like is to return results for the last 4 weeks instead. I could use "Quarter" but that will be affected at the year end.
So it is best to return the last 4 weeks data regardless of the year. I tried the datepart function but nothing is returned.

Code: Select all

SELECT DBA_JOB_CONTROL_VIEW.JobID, DBA_JOB_CONTROL_VIEW.VehicleMake, DBA_JOB_CONTROL_VIEW.VehicleModel, DBA_JOB_CONTROL_VIEW.VehicleReg, DBA_JOB_CONTROL_VIEW.JobDateOutExpected AS ECD, IIf(Not IsNull([CompletionDate]),DateValue([CompletionDate])) AS Completed, DatePart("ww",[Completed]) AS Week
FROM DBA_JOB_CONTROL_VIEW
WHERE (((IIf(Not IsNull([CompletionDate]),DateValue([CompletionDate])))>=Date()-155))
ORDER BY DBA_JOB_CONTROL_VIEW.JobDateOutExpected;
Can anyone assist?

Thanks
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78359
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Dates this quarter

Post by HansV »

If you want the last 4 weeks you could use Date()-28 instead of Date()-155
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Dates this quarter

Post by D Willett »

Hi Hans
Confused... I thought Date()-28 would return 28 days of data??
Cheers
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78359
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Dates this quarter

Post by HansV »

"What I would like is to return results for the last 4 weeks instead."

Uh - aren't 4 weeks equivalent to 28 days?
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Dates this quarter

Post by D Willett »

:rofl: Oh yes.................... sorry :drop: :hailpraise: brain not in gear ....

Cheers Hans
Cheers ...

Dave.