I'm having trouble with this. If I find an answer I'll include it in my post. SQL to calculate number of days in current quarter, for instance. I can't figure it with Crystal Syntax which is where I fall short.
for starters,
SQL to get 1st day of current quarter
SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), 0)
SQL to get last day of current quarter
SELECT DATEADD (dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) +1, 0))
update:
beginning of current quarter in Crystal syntax:
dateserial(year(currentdate),datepart('q',currentdate)*3-2,1)
end of current quarter
dateserial(year(currentdate),datepart('q',currentdate)*3+1,1-1)
Answer in all it's glory :)
DateDiff ("d", dateserial(year(currentdate),datepart('q',currentdate)*3-2,1),currentdate) -
DateDiff ("ww", dateserial(year(currentdate),datepart('q',currentdate)*3-2,1), currentdate, crSaturday) -
DateDiff ("ww", dateserial(year(currentdate),datepart('q',currentdate)*3-2,1), currentdate,crSunday)
shorthand of the final formula:
Datediff("d", startdate, enddate) -
Datediff("ww", startdate, enddate, crSaturday)-
Datediff("ww", startdate, enddate, crSunday);