Converting numbers to MM:SS format in Cross-tab - crystal-reports

I'm trying to convert a value in Cross-tab of Crystal report into a MM:SS format. I used the following steps: Right-click summary > Format Field > Display String > x+2
WhilePrintingRecords;
NumberVar curr := CurrentFieldValue;
NumberVar mins := Truncate(curr / 60);
NumberVar secs := Remainder(curr, 60);
ToText(mins, 0, "") & ":" & ToText(secs, 0, "")
The results are ok when the secs is not 0. Example: `4:30'
But, I am having problems when secs is 0, the result is (for 4 minutes): 4:0
I would like to have the output as 4:00, with the seconds display as always a 2 digit number.
Thank you for all your help

You my ElapsedTime function in conditional-formatting expression.

I used this instead, and it worked :)
NumberVar curr := CurrentFieldValue;
NumberVar mins := Truncate(curr / 60);
NumberVar secs := Remainder(curr, 60);
ToText(mins, 0, "") & ":" & ToText(secs, '00')

Related

Crystal Reports convert number to text

Using Crystal Reports version 8 and I need to convert a numbervar to stringvar. I have tried ToText() (with all variations of capitalization) and CStr() (also with various capitalizations) and each time CR tells me "A number is required here" and moves the cursor to the beginning of my else block. Ultimately trying to convert hours and minutes both stored as NumberVars to strings so I can display "8h 30m" instead of 8.50.
Here is what I have for the formula so far:
if {Collect2000Log.LogCode} = "0002" then 0
else
(
NumberVar OldTime := ((DateDiff("n",{#NextTime},{Collect2000Log.LogWhen})/60)*-1);
NumberVar Hours;
NumberVar Minutes;
StringVar strHours;
StringVar strMinutes;
StringVar NewTime;
//Extract the number of hours
Hours := Int(OldTime);
//Get the decimal portion for minutes
Minutes := Remainder(OldTime, 1) * 100;
//Divide the minutes by 60 to increase the number of hours
Hours := Hours + Int(Minutes / 60);
//Get the remainder for the number of minutes left over
Minutes := Remainder(Minutes, 60);
//Convert hours & mins to strings
strHours := ToText(Hours);
strMinutes := ToText(Minutes):
NewTime := strHours & "h " & strMinutes & "m";
);
And now when I add this formula CR says "The end ) is missing" and I'm stumped. I was able to get around that once but now not looking so hopeful.
Any help would be much appreciated!
Problem is simple... In an IF and Else you need to return same data type but you are returning a number through IF and a String through Else hence the error a Number is required at the starting of the else block.. so convert the output of If to string like below.
if {Collect2000Log.LogCode} = "0002"
then ToText(0)
else
(
NumberVar OldTime := ((DateDiff("n",{#NextTime},{Collect2000Log.LogWhen})/60)*-1);
NumberVar Hours;
NumberVar Minutes;
StringVar strHours;
StringVar strMinutes;
StringVar NewTime;
//Extract the number of hours
Hours := Int(OldTime);
//Get the decimal portion for minutes
Minutes := Remainder(OldTime, 1) * 100;
//Divide the minutes by 60 to increase the number of hours
Hours := Hours + Int(Minutes / 60);
//Get the remainder for the number of minutes left over
Minutes := Remainder(Minutes, 60);
//Convert hours & mins to strings
strHours := ToText(Hours);
strMinutes := ToText(Minutes):
NewTime := strHours & "h " & strMinutes & "m";
);

Trying to convert total minutes from a datediff to days, remaining hours, & minutes in Crystal Reports

I am using Crystal Reports 2013 SP5 on Windows 7 Pro pulling from an Oracle db.
I am trying to write a formula(s) in crystal reports that returns the total number of days the remaining hours if less than 24, and the remaining minutes if less than 60 from a datediff between two date time fields.
So far I have managed to show the total number of minutes as days, hours, and minutes:
local numbervar tm := datediff('n',{table.date1},{table.date2},0);
local numbervar h := truncate(tm/60,0);
local numbervar d := truncate(tm/1440,0);
local stringvar tm_d := totext(d,0,"") + ' days ';
local stringvar tm_h := totext(h,0,"") + ' hours ';
local stringvar tm_m := totext(tm,0,"") + ' minutes ';
local stringvar tm_string := tm_d & tm_h & tm_m
Returns: 183 days 4393 hours 263633 minutes
183 days which is = to 4393 hours which is = to 263633 minutes
What I need it to do is show 183 days (not rounded) and any remaining hours (not rounded) and any remaining minutes (not rounded) so it looks something like this:
The difference between table.date1 and table.date2 is:
183 days 4 hours 23 minutes (just used random hours and minutes)
Just try this also.
local numbervar tt := datediff('n',{table.DATE1},{table.DATE2});
local numbervar d := truncate(tt/1440,0);
local numbervar h := truncate(remainder(tt,1440)/60,0);
local numbervar m := truncate(remainder(tt,60),0);
local stringvar tt_d := if d=0 then "" else totext(d,0,"") + 'd ';
local stringvar tt_h := if h = 0 then "" else (totext(h,0,"")) + 'h ';
local stringvar tt_m := totext(m,0,"") + 'm ';
local stringvar tt_string := tt_d & tt_h & tt_m
Refer links :
http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=15879
http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=10279
http://www.experts-exchange.com/Database/Reporting/Crystal_Reports/Q_24014196.html
Have no experience with your system, but definitely you'll need this:
totalMinutes = 263633
days = floor (totalMinutes /(24*60))
hours = floor (totalMinutes %(24 * 60) /(60))
minutes = floor (totalMinutes % 60)
where % is MOD (ex: 15 MOD 4 = 3)
as far as I see, floor is same as truncate, and quick lookup gave, that MOD is MOD like A MOD B

crystal report: print missing records

i want to print missing records in crystal report .
i am using below formula in the report and i have placed this formula in details b section.
details a has normal report fields.
formula:
local numbervar firstemp; // first Emp#
local numbervar nextemp; // next Emp#
local numbervar diff; // difference between firstemp and nextemp
local numbervar increase; // increment for missing Emp#'s
local numbervar result;
increase := 0;
firstemp := tonumber({getRptSalesSummery;1.Bill_Id});
nextemp := tonumber(next({getRptSalesSummery;1.Bill_Id}));
nextemp := nextemp -1;
diff := nextemp - firstemp;
if nextemp = firstemp
then ""
else (
while diff >= 1
do (
diff := diff - 1;
increase := increase + 1;
result := firstemp + increase;
exit while;
);
totext (result,"0000") & chr(13);
)
this formula is not giving me range.
for example if in report there is range of 1 to 10 and 6,7,8,9 is missing records, then if i check in the report its printing 1 to 5 and 6 as missing then directly 10, but its not giving me 7,8,9.
basically i required range of missing records

Crystal Reports Formula to generate a random number

Let assume
x = 1001
Now I am inputting x to my code and generating y in the following order:
Length of 1001 is 4 so starting from the last number
i.e. 1(number) * 4(position of number) & 0 * 3 & 0 * 2 & 1 * 1 that gives a new number 4001
Another eg. 1234 gives 16941
In crystal I am creating a formual as follows:
stringvar tmp_EventNo;
stringvar tmp_Password;
numbervar i;
numbervar m_password;
tmp_EventNo = Trim(ToText({GR_EVENT.event_number}));
For i := Len(tmp_EventNo) To 1 Step -1 Do
(
tmp_PassWord = tmp_PassWord & Trim(ToText(Val(Mid(tmp_EventNo, i, 1)) + i));
);
m_Password = Val(tmp_PassWord);
m_password
But it doesnt seem to work. Just results in 0.00
Please help thanks in advance
Nice easy one- you will kick yourself :)
In Crystal = is used for evaluation. := is used for assignment.]
There were a few other issues with the code so i tweaked it for you:
stringvar tmp_EventNo;
stringvar tmp_Password;
numbervar i;
numbervar m_password;
tmp_EventNo := Trim(ToText({GR_EVENT.event_number}, 0, ''));
For i := Len(tmp_EventNo) To 1 Step -1 Do
(
tmp_PassWord := tmp_PassWord & Trim(ToText(Val(Mid(tmp_EventNo, i, 1)) * i,0));
);
m_Password := Val(tmp_PassWord);
tmp_PassWord;

Crystal 2011 - Convert Ticks to Time

I've got a Crystal Report (2011) that uses a Stored Procedure to display some data. One of the fields is TimeSpent (bigint) and it holds the number of Ticks in a TimeSpan (in C#, we pass TimeSpan.Ticks to the DB to be stored).
Obviously on my report I wouldn't want to show this, so I am wondering how I can convert ticks to read dd:hh:mm:ss, e.g. 01:05:58:25 for 1 day, 5 hours, 58 minutes and 29 seconds?
A tick is 100 nanoseconds, or 10 million ticks per second. So first convert to seconds
numbervar span := {field.ticks}/10000000;
From there, just break the seconds down into time pieces (This snippet is from tek-tips):
numbervar days;
numberVar hrs;
numberVar min;
numberVar sec;
stringVar ddhhmmss;
days:= Truncate(Truncate(Truncate(span/60)/60)/24);
hrs := Remainder(Truncate(Truncate(span/60)/60),24);
min := Remainder(Truncate(span/60),60);
sec := Remainder(span,60);
ddhhmmss := totext(days,0,"") + ":" + totext(hrs,"00") + ":" + totext(min,"00") + ":" + totext(sec,"00");
ddhhmmss