Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Military time to Standard time

Status
Not open for further replies.

jschill2628

Programmer
Nov 3, 2009
156
US
Hi I am trying to convert Military time to Standard time, from a previous post I have had help and have come up with the following

Numbervar T := ToNumber({IRSCLAIM.MISC4_DESC});
T := if isnull({IRSCLAIM.MISC4_DESC})
then 0 else T;
stringvar n := totext(T,'0000');
numbervar Hs := ToNumber(left(n,2));
numbervar Ms := toNumber(right(n,2));
time(hs,ms,0)


my problem is that when running the rreport, it shoots back with an error message
"Hour must be between 0 and 23"

I am using Crystal Reports XI Release 2
 
try modifying your code to this


Numbervar T := ToNumber({IRSCLAIM.MISC4_DESC});
T := if isnull({IRSCLAIM.MISC4_DESC})
then 0 else T;
T := if T =2400 then 0 else T;
stringvar n := totext(T,'0000');
numbervar Hs := ToNumber(left(n,2));
numbervar Ms := toNumber(right(n,2));
time(hs,ms,0)

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 
Crystal 10. I need to convert a string-type field that contains mililary time to standard time. I tried the above formula, but get the message "the string is non-numeric" and it highlights: ToNumber ({TC1_TimecardMastefile.TimePunchedOut});
Can anyone tell me what is the problem?
 
That sounds like it is telling you that {TC1_TimecardMastefile.TimePunchedOut} is already a number

take the tonumber part out:
//
Numbervar T := {IRSCLAIM.MISC4_DESC};
T := if isnull({IRSCLAIM.MISC4_DESC})
then 0 else T;
T := if T =2400 then 0 else T;
stringvar n := totext(T,'0000');
numbervar Hs := ToNumber(left(n,2));
numbervar Ms := toNumber(right(n,2));
time(hs,ms,0)

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 
Actually, {TC1_TimecardMastefile.TimePunchedOut} is a string-type field. And when I take out the ToNumber function, Crystal responds "a number is required here". The values in the field are, for example, 10.62 and 11.98. So, I really don't understand why I'm getting "the string is non-numeric" with the ToNumber function.
 
You need to do the null check before the first reference to the field. Try changing your formula to:

Numbervar T;
if isnull({IRSCLAIM.MISC4_DESC}) then
T := 0 else
T := ToNumber({IRSCLAIM.MISC4_DESC});
stringvar n := totext(T,'0000');
numbervar Hs := ToNumber(left(n,2));
numbervar Ms := toNumber(right(n,2));
time(hs,ms,0)

-LB
 
You put me on the right trail. Turns out I needed to check for blank, in addition to null. Thank you for your help.
 
so a month later and my report is acting up on me.....

Numbervar T := ToNumber({IRSCLAIM.MISC4_DESC});
T := if isnull({IRSCLAIM.MISC4_DESC})
then 0 else T;
T := if T =2400 then 0 else T;
stringvar n := totext(T,'0000');
numbervar Hs := ToNumber(left(n,2));
numbervar Ms := toNumber(right(n,2));
time(hs,ms,0)

My problem now is that when I try to export it it highights the last line (time(hs,ms,0))and tells me that the minutes have to be between 0 and 59.
 
You must do the null check first (before referencing the field in any other way), as in:

Numbervar T;
if isnull({IRSCLAIM.MISC4_DESC}) then
T := 0 else
T := ToNumber({IRSCLAIM.MISC4_DESC});
stringvar n := totext(T,'0000');
numbervar Hs := ToNumber(left(n,2));
numbervar Ms := toNumber(right(n,2));
time(hs,ms,0)

-LB
 
I think the problem might be if people have put a character in place of a variable , such as putting xxxx, instead of 1010. Holw would I fix something like that
 
Try this:

Numbervar T;
if isnull({IRSCLAIM.MISC4_DESC}) or
trim({IRSCLAIM.MISC4_DESC}) = "" or
not isnumeric({IRSCLAIM.MISC4_DESC}) then
T := 0 else
T := ToNumber({IRSCLAIM.MISC4_DESC});
stringvar n := totext(T,'0000');
numbervar Hs := ToNumber(left(n,2));
numbervar Ms := toNumber(right(n,2));
time(hs,ms,0)

-LB
 
when I try that it still gives me an error message
"Minutes must be between 0 and 59
 
I think you need to show a sample of how this field can appear. Can it ever be less or more than 4 characters long?

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top