Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateTime Var

Status
Not open for further replies.

bld21

Technical User
Mar 1, 2010
49
US
I am using crystal reports 2008. I am calcuating the number of business days between two dates using the formula below:

WhileReadingRecords;
Local DateVar Start:= date({s_srv_req.CREATED});
Local DateVar End:= date({s_srv_req.ACT_CLOSE_DT});
Local Numbervar Days;
Local Numbervar Weeks;
Local Numbervar Hol;
Datevar Array Holidays;

Weeks:=(Truncate(End-dayofWeek(End) + 1
-(Start - dayofWeek(Start) + 1))/7)*5;
Days:=DayOfWeek(End)-DayOfWeek(Start) +
(if DayOfWeek(Start) = 1 then -1 else 0) +
(if DayOfWeek(End) = 7 then -1 else 0);

Local NumberVar i;
For i:=1 to Count(Holidays)
do (if DayOfWeek( Holidays ) in 2 to 6 and
Holidays in start to end then Hol:=Hol+1);

Weeks + Days - Hol

Everything works fine. Except now I need to figure out how to use the DateTimeVar instead of the DateVar. I want to show anything less than 24 hours would be considered 0 days. So if the create date was 10/4 at 5:00pm and the closed date was 10/5 at 9:00am it should show 0 days because it was less than 24 hours. Right now it shows as a 1 day difference, because I was not thinking in terms of hours versus days.

I am thinking I need to use something like:

Local DateTimeVar Start:= date({s_srv_req.CREATED}, time(#08:00am);
Local DateTimeVar End:= date({s_srv_req.ACT_CLOSE_DT}, time (#17:00pm);

Any ideas?
Thanks to all!!!
 
Take a look at DateDiff, that will do it for you.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 11.5 with SQL and Windows XP [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top