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

How can I format the DateTimeDiff output?

Status
Not open for further replies.

ms1746

MIS
Sep 9, 2003
13
0
0
US
This is the standard output format for the DateTimeDiff:

0 Day(s), 0 Hour(s), 0 Minute(s), 0 Second(s)

Is there anyway to make the output look like this:

00 Day(s), 00 Hour(s), 00 Minute(s), 00 Second(s)

The problem I am running into is that I am trying to count a number of records that fall within a certain time frame say less than:

0 Day(s), 4 Hour(s), 0 Minute(s), 0 Second(s)

It works on everything except rows that have a two digit hour such as:

0 Day(s), 21 Hour(s), 0 Minute(s), 0 Second(s)

Any help would be appreciated!

MSteele [sadeyes]
 
Dear msteele,

What version of Crystal? 8.0 and higher can use DateDiff and then a formula to transform. I believe the DateTimeDiff is a UFL which provides this as an add'l function. I use datediff to retrieve the difference between two dates in seconds and transform that to DD:HH:MM:SS.

Hope this helps,

//Convert Total Seconds to DD:HH:MM:SS
//Remove comment tags to format in
//Days X, Hours X, Minutes X, Seconds X
//and add comment tags or delete DD:HH:MM:SS formating.

NumberVar TotalSec := Datediff("s", {Table.Date1,Table.Date2);
NumberVar Days := Truncate (TotalSec / 86400);
NumberVar Hours := Truncate (Remainder ( TotalSec,86400) / 3600);
NumberVar Minutes := Truncate (Remainder ( TotalSec,3600) / 60);
NumberVar Seconds := Remainder ( TotalSec , 60);

//comment or delete the following to format it
//with the text instead of looking like 12:05:21:05
Totext ( Days, '00', 0,'') + ':'+
Totext ( Hours, '00', 0,'') + ':'+
Totext ( Minutes,'00', 0,'') + ':'+
Totext ( Seconds,'00', 0,'')

//'Day(s) ' + Totext ( Days, '00', 0,'') + ' ' +
//'Hour(s) ' + Totext ( Hours, '00', 0,'') + ' ' +
//'Minute(s) ' + Totext ( Minutes,'00', 0,'') + ' ' +
//'Second(s) ' + Totext ( Seconds,'00', 0,'')

Regards,

ro


Rosemary Lieberman
rosemary@microflo.com, Microflo provides expert consulting on MagicTSD and Crystal Reports.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top