Professional Documents
Culture Documents
How do you create a formula in Crystal Reports (CR) that adds more than
one time field and displays the total in the same format: hh:mm:ss?
For example:
1:45:01 + 1:45:01 should display 03:30:02 and not 2:90:02
Solution
In order to get the sum of more than one time field and to display the
total of the time field in the same format (hh:mm:ss) you must complete
the following steps:
A. Convert all the time fields to a common time unit such as seconds
B. Calculate the total time in seconds
C. Convert the seconds back to hh:mm:ss format.
// Parse out the hours portion of the string and multiply by 3600 to convert to seconds
hours := tonumber({timestringfield}[1 to 2])* 3600;
// Parse out the minutes portion of the string and multiply by 60 to convert to seconds
minutes := tonumber({timestringfield}[4 to 5]) * 60;
// Subtract the Hours and Minutes and what is left over is seconds.
Seconds := {@Totalseconds} - (Hours * 3600) - (Minutes * 60);
2
Reset the variable in header:
Global numbervar x;
x:=0;
Now write your formula in formula filed and place as a last field in detail
section:
Global numbervar x;
x:=x+databasefield;
Global numbervar x;
x
3
Pt numerotare randuri:
1st Formula: HeaderReset - This formula should be placed in the page header
of the report. It will reset the counter when the report is processed to the next
page. Counter is a variable that stores the number as the report processes
each record.
WhilePrintingRecords;
NumberVar counter:=0
WhilePrintingRecords;
NumberVar counter;
counter:=counter+1
WhilePrintingRecords;
Global NumberVar Counter;
Counter := Counter + 1;
"Part " & ToText(Counter),0)
https://www.mindstick.com/Articles/614/running-total-field-in-crystal-
report
5
Converting total seconds in the format of DD:HH:MM:SS:
Converting total seconds to a formatted "elapsed time" string:
When you need to display an elapsed time in the format of DD:HH:MM:SS, you
can convert the time value to a total seconds number and use the following
formula to convert the seconds total to a formatted string. All you need to do
is replace the dummy field on the end of the second line with your net seconds
or total seconds field. I am using WhilePrintingRecords but you can use
WhileReadingRecords in cases where the {YourTable.TotalSeconds} field does
not involve a Crystal Summary operation like Sum() or Average().
WhilePrintingRecords;
NumberVar TotalSec := {YourTable.TotalSeconds};
NumberVar Days := Truncate (TotalSec / 86400);
NumberVar Hours := Truncate (Remainder ( TotalSec , 86400) / 3600) ;
NumberVar Minutes := Truncate (Remainder ( TotalSec , 3600) / 60) ;
NumberVar Seconds := Remainder (TotalSec , 60) ;
If you want to display only in hours and minutes you should use this version:
WhilePrintingRecords;
NumberVar TotalSec := {YourTable.TotalSeconds};
formula:
//for display the time to the closest quarter hour
local timeVar ti:={DB.Field};//database field(if it is date field use
time({DB.Field}))
numberVar min:= Minute(ti)/15;
numberVar RoundMin:=Truncate(min+0.5)*15;
time(hour({DB.Field}),RoundMin,00)
sau :
Sau:
Ex: daca vreau sa rotunjesc 07:31:42 la 08:00:00 (adica peste 30 min sa fie 1
ora)
whileprintingrecords;
numberVar dur := {@DateDiff};
numberVar hrs;
numberVar min;
numberVar sec;
stringVar hhmmss;
hrs := Truncate(Truncate(dur/60)/60);
min := Remainder(Truncate(dur/60),60);
if min in 01 to 29 then min := 00 else
if min in 30 to 59 then
(min := 00;
hrs := hrs + 1) else
min := min;
hhmmss := totext(hrs, "0") + ":" + totext(min, "00") + ":" + totext(sec, "00");
hhmmss
7
Eliminare zile weekend si concediu:
/Main formula:
WhileReadingRecords;
Local DateVar Start := {StartDate}; // place your Starting Date here
Local DateVar End := {EndDate}; // place your Ending Date here
Local NumberVar Weeks;
Local NumberVar Days;
Local Numbervar Hol;
DateVar Array Holidays;
Weeks:= (Truncate (End - dayofWeek(End) + 1
- (Start - dayofWeek(Start) + 1)) /7 ) * 5;
Days := DayOfWeek(End) - DayOfWeek(Start) + 1 +
(if DayOfWeek(Start) = 1 then -1 else 0) +
(if DayOfWeek(End) = 7 then -1 else 0);
Local NumberVar i;
For i := 1 to Count (Holidays)
do (if DayOfWeek ( Holidays[i] ) in 2 to 6 and
Holidays[i] in start to end then Hol:=Hol+1 );
Weeks + Days – Hol
https://kenhamady.com/formulas/default.html
8
Introducere luna in pagina dupa un parametru
9
Conversie timp (format “number”) in timp
10
Conversie “number ” la “string”
Ex:
Number totext({number}) totext({number},0,””)
108 108,00 108