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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to get diff between two datetimes

Status
Not open for further replies.

darkradar

Programmer
Jul 20, 2002
78
US
Hi

I have created timeclock form.It had 4 fields.
punchindate,punchintime,punchoutdate,punchouttime.
I want the difference between punchindate,time and
punchoutdate,time.
Anybody gives me an idea what kind of formula I have to
use to get the duration of time.
I used many formulas like datevalue, datadiff .
But they didn't work .
I am giving an example of the formula that I have used.
'****************************************************
DateTimeValue ({Timeclock.punchindate}, {Timeclock.punchintime})-DateTimeValue ({Timeclock.punchoutdate},{Timeclock.punchouttime} )
'****************************************************

Any help will be highly appreciated.
Thanks in advance.
 
Dear Darkradar:

My suggestion would be to get the difference in seconds and then use a formula to transform that to d:h:m:s

So standalone the formula for seconds would be:
datedif("s", ({Timeclock.punchindate}+ {Timeclock.punchintime}),({Timeclock.punchoutdate}+{Timeclock.punchouttime} )

The above will return the number of seconds between the two datetimes.

However, I would use that calc in the following formula to show the d:h:m:s.

//begin formula
WhilePrintingRecords;
NumberVar TotalSec := datedif("s", ({Timeclock.punchindate}+ {Timeclock.punchintime}),({Timeclock.punchoutdate}+{Timeclock.punchouttime});
NumberVar Days := Truncate (TotalSec / 86400);
NumberVar Hours := Truncate (Remainder ( TotalSec,86400) / 3600);
NumberVar Minutes := Truncate (Remainder ( TotalSec,3600) / 60);
NumberVar Seconds := Remainder ( TotalSec , 60);

Totext ( Days, '00', 0,'') + ':'+
Totext ( Hours, '00', 0,'') + ':'+
Totext ( Minutes,'00', 0,'') + ':'+
Totext ( Seconds,'00', 0,'')

//end formula

Hope that helps,

ro

Rosemary Lieberman
rosemary@microflo.com, Microflo provides expert consulting on MagicTSD and Crystal Reports.
 
Sounds like you could put the date and time fields togather into a pinchInDateTime, PunchDate time and then use datediff to get the inetval in whatever unit you need. I would guess hours or minutes which you could convert to hours and minutes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top