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

Diff between StartTime & EndTime. Time diff only not date 1

Status
Not open for further replies.

Eveline75

Programmer
Mar 6, 2008
5
US
I have two seperate fields as STARTTIME and ENDTIME, both are datatime datatype and I am using Crytstal reports XI.

Example:-
STARTTIME 02/10/2005 12:10:00 AM (this is a predefined in year 2005, but we need to take only the time)
ENDTIME 01/01/2008 11:30:00 PM (this is current year, so take just the time)

Now i need the ONLY the time difference between the both the time, like
TOTALTIME = STARTTIME - ENDTIME
= (12:10:00 AM) - (11:30:00 PM) = -11:20:00

Then I did convert them into 12:10:00 AM and 11:30:00 PM respectively using CTime

Now I should get the time difference between them as -/+ hh:mm:ss with a negative sign (-) if it’s late and a positive sign (+) if it’s before time.

please help....I need it badly. I tried using the datediff, it did not work since the STARTTIME date is in 2005.
I need only the time difference.

Thanks-in-advance,
Eve


 
Your time difference result makes no sense. You can use date diff like this, if you just want to compare times:

//{@diff}:
datediff("s",datetime(currentdate,time({table.endtime})),datetime(currentdate,time({table.starttime})))

Then you can convert the result back to a string by using faq767-3543:

whileprintingrecords;
numberVar dur := {@diff};
numberVar hrs;
numberVar min;
numberVar sec;
stringVar hhmmss;

hrs := Truncate(Truncate(dur/60)/60);
min := abs(Remainder(Truncate(dur/60),60));
sec := abs(Remainder(dur,60));
hhmmss := totext(hrs,"00") + ":" + totext(min,"00") + ":" + totext(sec,"00");
hhmmss

-LB
 
Thanks alot, it works perfect.

But i also need the positive sign before the hh:mm:ss when the time is before ONtime
Example:
Goal_press_ONtime - Press_Actual_ONtime
11:45:00 PM - 11:30:00 PM = +00:15:00
Now i just get 00:15:00

And i also want the percentage of the delay time with the mins and hour included. Please help.

Thanks,
Eve
 
whileprintingrecords;
numberVar dur := {@diff};
numberVar hrs;
numberVar min;
numberVar sec;
stringVar hhmmss;

hrs := Truncate(Truncate(dur/60)/60);
min := abs(Remainder(Truncate(dur/60),60));
sec := abs(Remainder(dur,60));
hhmmss := totext(hrs,"00") + ":" + totext(min,"00") + ":" + totext(sec,"00");
if hhmmss[1] = '-' then
hhmmss else
"+"+hhmmss

Percentage of what? What have you tried so far?

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top