Converting Seconds into Days: Hours: Minutes: Seconds Format at Crystal Reports -2008
Business Requirement: – To create a corresponding output column at the report which takes the input as the source column (value in seconds) and gives the output in the below format
Days: Hours: Minutes: Seconds
To achieve the above requirement we need to follow below steps.
1) Connect your Report to the source data base.
2) Pull the required tables from the source database say Table WORK in above case.
3) Place all the required fields at the detail section of the report.
4) Let us say that the source field which has the required source information data is WORK. Seconds. (Here WORK. Seconds will have integer data type and will store total number of seconds).
5) To achieve the Days: Hours: Minutes: Seconds format for the corresponding output column for WORK. Seconds we would be required to create a new formula field say fr_DHMS.
6) For creating the new formula do the below actions
a) Go to the Formula section at Field Explorer and right click to create a new formula with a name fr_DHMS.
b) A new formula window with function/Databasefileds /Operators options will open up .Place the below code at this window
NumberVar TotalSec: = WORK. Seconds;
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, ‘##’) + ‘: Day’ +
Totext (Hours, ‘00’) + ‘: Hours’ +
Totext (Minutes, ‘00’) + ‘: Minutes’ +
Totext (Seconds, ‘00’) + ‘: Seconds’.
c) Finally validate the formula and click on save.
7) Place the newly created formula at the detail section of the report where the other required fields from the source table are placed.(We can customize the header text for the corresponding output column as per the requirement)
8) Now run the report.
The New output column will give the corresponding equivalent value in form of Days: Hours: Minutes: Seconds format after converting the input value which is in the form of seconds from input source column WORK.Seconds.