I have a time field which displays as the following:
9:50:03 is 95003
14:53:44 is 145344
So when it's a single digit hour, the value is only 5 characters vs double digit hour is 6 characters.
I need to convert 95003 to 9:50 and 145344 to to 14:53 following this formula for any time.
If I were to do this in any language I would parse the data by 2 digits and add a : to each part. I would need to know what language to help you though. Or if it does not matter please emphasize.
This is very general without seeing your formula, but this is how I would go by doing it.
EDIT:
NumberVar dur := Sum ({#elapsed});
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");
Second Try
datediff("s",datetime(date({table.occdate}),{#enroutetimetotime}),datetime(date({table.inservicedate}),{#inservicetimetotime}))
OR - Probably your best shot
numbervar ntt := {YourTable.NumberField};
stringvar nttx := totext(ntt,"000000");
time(val(left(nttx,2)),val(mid(nttx,3,2)),val(right(nttx,2)))
Related
I've been searching your questions for a while, finding the answers to many of my own. But I can't find any help with these:
1-We recently migrated to Windows 10, and following that there are a few reports that work just fine for my coworker but not me. Most of our reports work fine either way. So far as we can tell, we have the same setup, same drivers, same ODBC connections, same versions, everything. Only I get no data, and he gets data. I don't get any error messages, just the report returns with all 0s when we know there is data to find.
2-Also, we have reports that pull from Outlook folders which also no longer work. We are getting a "non-numeric string" error for a field that returns a date and did not throw any errors before the migration. We are only able to return data from before the migration. When running those reports from a Windows 7 machine, we get the same issues plus a MAPI error pop up.
For the affected reports, I have re-built them from scratch on the Win 10 machine to no avail. We are scratching our heads about this, and think it has to be something on the backend that we don't have access to, but not sure what to bring up to the Sys Admin for resolution. Any advice would be greatly appreciated!
Formula with non-numeric string error (formula previously worked without issue):
whileprintingrecords;
shared stringvar Monthpart;
shared numbervar Monthnum;
shared stringvar daypart;
shared numbervar daynum;
shared stringvar Yearpart;
shared numbervar yearnum;
shared numbervar hournum;
shared stringvar hourpart;
shared numbervar minpart;
shared numbervar IdPmAm;
shared datetimevar date2;
//Parse out data
Monthpart := {#Date}[1 to 2];
daypart := ToText({#Date}[4 to 5]);
Yearpart := ToText({#Date}[7 to 10]);
If (Instr({#Date},":")-Instr({#Date}," ")) = 3 then
(hournum := tonumber({#Date}[12 to 13]);
Minpart := tonumber({#Date}[(Instr({#Date},":")+1) to (Instr({#Date},":")+2)]))
else if (Instr({#Date},":")-Instr({#Date}," ")) = 2 then
(hournum := tonumber({#Date}[12]);
Minpart := Tonumber({#Date}[(Instr({#Date},":")+1) to (Instr({#Date},":")+2)]))
else if (Instr({#Date},":")-Instr({#Date}," ")) = 0 then
(hournum := 0;
Minpart := 0;);
IdPmAm :=(Instr({#Date}, ":")+ 4);
If ({#Date}[IdPmAm] = "P" and hournum <> 12) then
hournum := hournum + 12;
//Change data to numbers
If NumericText(MonthPart) then Monthnum := tonumber(Monthpart);
If NumericText(DayPart) then Daynum := tonumber(Daypart);
If NumericText(YearPart) then yearnum := tonumber(Yearpart);
Date2 := datetimevalue(Yearnum, Monthnum, Daynum, hournum, minpart, 00)
I've been working on a report made by someone else which uses the StDev function. I thought it would be simple enough, but the data can contain multiple values for each record, so there are if statements used to determine which value to take from each record. I've exported a table to Excel which contains one value per record (the one that should be used in the StDev), and then calculated the SD there to provide a check.
The report and Excel are giving me very different values :(
So, I'm going back to the report and using some additional formula fields to calculate the SD longhand to act as a kind of deciding vote (fingers crossed it doesn't produce a third set of values...).
I've worked out the syntax errors, but am still getting a run-time error - "Division by zero" which then highlights the section of code indicated below...
My formula fields are:
{#StDevArrayPopulate} - in the details section
NumberVar Array varStDevArray;
NumberVar varStDevArrayCount;
varStDevArray [varStDevArrayCount] := {ValueToSummarise};
varStDevArrayCount := varStDevArrayCount + 1;
{#StDevArrayCalculate} - in the group footer
NumberVar Array varStDevArray;
NumberVar varCounter :=1;
NumberVar varMean := 0;
NumberVar varStDev := 0;
NumberVar varStDevArrayCount;
// START OF MEAN
// Sum of all of the values in the array
for varCounter:= 1 to varStDevArrayCount step 1 do
(
varMean := varMean + varStDevArray [varStDevArrayCount];
);
// Divide by the total number of values in the array
varMean := varMean / varStDevArrayCount; // !! This is the line that highlights after the error message !!
// END OF MEAN
// START OF STANDARD DEVIATION
// Subtract the mean from each value in the array and square the result
for varCounter := 1 to varStDevArrayCount step 1 do
(
varStDevArray[varStDevArrayCount] := (varStDevArray [varStDevArrayCount] - varMean) * (varStDevArray [varStDevArrayCount] - varMean);
);
// Sum of all of the values in the array
for varCounter:= 1 to varStDevArrayCount step 1 do
(
varStDev := varStDev + varStDevArray [varStDevArrayCount];
);
// Divide by the total number of values in the array
varStDev := varStDev / varStDevArrayCount;
// Square root of mean of differences
varStDev := Sqr(varStDev)
// END OF STANDARD DEVIATION
{#StDevArrayCalculate} - in the group footer
NumberVar varMean;
NumberVar varStDev;
"The mean is " & varMean & ", and the standard deviation is " & varStDev & "."
I've tried using a Running Total field but that was giving errors as it need to be count the first record before the Populate formula field ran. I've also tried adding a fourth field to the header, which initialises the varStDevArrayCount as 1.
Does anyone have any suggestions?
Looks like there are no detail records hence you are getting zero in array... I don't think initializing with 1 will make any difference instead make a small change like below and check.
if varStDevArrayCount=0
then
varMean :=varMean
else
varMean := varMean / varStDevArrayCount;
I would advice you to just check records in detail and then debug
I'm new to crystal so please excuse me if this is a stupid question. I've got a database field in Sage ERP which is the time, stored as a GMT time, the field type is number. So for example the data in the filed will be 8461110 (08:46) or 13021054 (13:02). Now in crystal I need to convert this field to time because I need to select data between 2 times. I've struggled with this yesterday for the whole time, but no luck.
I've created a formula field with the following code but the result I get is 00:00:00
Local NumberVar TheHour;
Local NumberVar TheMin;
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheHour = ToNumber(Left(ToText({ICHIST.AUDTTIME}),2))
else
TheHour = ToNumber(Left(ToText({ICHIST.AUDTTIME}),1));
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheMin = ToNumber(Mid(ToText({ICHIST.AUDTTIME}),3,2))
else
TheMin = ToNumber(Mid(ToText({ICHIST.AUDTTIME}),2,2));
Time(TheHour,TheMin,00);
What am I doing wrong, why is the result 00:00:00?
Problem is you are missing this :. In crysal reports whenever you want to assign a value to a variable syntax would be :=. So your formula will be
Local NumberVar TheHour;
Local NumberVar TheMin;
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheHour := ToNumber(Left(ToText({ICHIST.AUDTTIME}),2))
else
TheHour := ToNumber(Left(ToText({ICHIST.AUDTTIME}),1));
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheMin := ToNumber(Mid(ToText({ICHIST.AUDTTIME}),3,2))
else
TheMin := ToNumber(Mid(ToText({ICHIST.AUDTTIME}),2,2));
Time(TheHour,TheMin,00);
I need a formula that would multiply {table.time} * {table.cost}.
This is what I tried :
tonumber ({#timeformat}) * {Table.cost}
Formula for {#timeformat}
whileprintingrecords;
numberVar hrs;
numberVar min;
stringVar hhmm;
hrs := Remainder(Truncate({table.time}/60),60);
min := Remainder({table.time},60);
hhmm := totext(hrs,"00") + ":" + totext(min,"00");
hhmm
When I simply do that I get a string error from Crystal when I run the report.
String is non-numeric.
Any help is greatly appreciated.
Thanks
Your function {#timeformat} is producing strings that look like 02:30. They're useful for readability, but they're not numeric, nor can you multiply them.
Instead, try:
{table.time} * {table.cost}
I need to extract a date out of a invoice number and subtract one month from the month.
For example if a invoice number is I2011101002683 I need to pull out the 2011, four numbers starting a position 1, and then the 10, two numbers starting a position 5.
and display the date in a 2011/09 format. Thanks in advance.
One way:
numbervar year_start := 2;
numbervar year_len := 4;
numbervar month_start := year_start + year_len;
numbervar month_len:= 2;
mid({Command.InvoiceNumber},year_start,year_len) + "/" +
mid({Command.InvoiceNumber},month_start,month_len);
Create a formula field to extract the date:
//{#invoice_date}
//I|2011|10|1002683 --> Date(2011, 10, 1)
Date(ToNumber({Command.InvoiceNumber}[2 To 5]), ToNumber({Command.InvoiceNumber}[6 to 7]), 1)
Add the resulting formula to the canvas; format it as desired.