Crystal Report Convert Time Format From Seconds to HH:MM:SS

Some of the Crystal report that I need to generate involve conversion between Seconds to Hours:minutes:seconds.
I spend quite a long time to search on internet and work out how to do it and experienced some bugs on one of the Crystal Report formula that I build before had a bug.
I am not sure why it only works on some computer, but not the other.
E.g. it always display 2 decimal places at the end i.e. 1.00. (Although I use Mod to retrieve the reminder of the number, which mean it should not have any decimal place at all)
Anyway, here it is the formula/code that I use to convert Seconds to HH:MM:SS
Hope you find it useful:

numberVar dur;
dur := {Field/Value/Seconds you want to convert};
numberVar hrs;
numberVar min;
numberVar sec;
stringVar hhmmss;

hrs := Truncate(Truncate(dur/60)/60);
min := Remainder(Truncate(dur/60),60);
sec := Remainder(dur,60);

hhmmss := totext(hrs,”00″) + “:” + totext(min,”00″) + “:” + totext(sec,”00″);

hhmmss

Leave a Reply