MariaHalt
asked on
CTime({ado.x}) returning "12:00 AM" for all {ado.x}
CTime({ado.x}) returning "12:00 AM" for all {ado.x}. The CTime function takes number or string arguments. My argument is an integer that can range from 0 to 2399. No matter what the integer value, CTime is returning "12:00 AM"! This doesn't do what I think it should do. All I want is for it to return the time on a 12-hour clock.
By the way...
I checked Format Field and the sample at the bottom of the Date/Time tab is the correct time format I desire.
I've tried CTime(CStr({ado.x})) and get a bad time format string.
I've also IsTime({ado.x}) and it's returned True.
So what gives??? Please help.
By the way...
I checked Format Field and the sample at the bottom of the Date/Time tab is the correct time format I desire.
I've tried CTime(CStr({ado.x})) and get a bad time format string.
I've also IsTime({ado.x}) and it's returned True.
So what gives??? Please help.
ASKER
In a formula in my Crystal report. Version 8.5.
Can you provide some sample values for {ado.x}?
GusDarino
GusDarino
ASKER
They range from 0 to 2359. Like, 930, 1100, 1415, 2130.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect!
OK that makes more sense now. You originally listed 0 to 2359.
I am assuming then that:
930 = 9:30 am
1100 = 11:00 am
1415 = 2:15 pm
2130 = 9:30 pm
I assume that whole hours such as 1:00 pm are listed as 1300 and 9:00 am as 900.
The integer stores time in military format with hours and minutes only.
If my assumptions are correct then you can do the following:
Create a formula as follows:
if len(totext({Ado.x})) = 4 then TimeSerial(0,(tonumber(rig ht(totext( {Ado.x}),2 ))),(tonum ber(left(t otext({Ado .x}),2))*3 600)) else
if len(totext({Ado.x})) = 3 then TimeSerial(0,(tonumber(rig ht(totext( {Ado.x}),2 ))),(tonum ber(left(t otext({Ado .x}),1))*3 600)) else
if len(totext({Ado.x})) = 2 then TimeSerial(0,{Ado.x},0) else
TimeSerial(0,0,({Ado.x}*36 00))
Put the formula in the report and it should give you what you are looking for. I am sure there are other ways of getting the same results. This is just what came to mind.
GusDarino
I am assuming then that:
930 = 9:30 am
1100 = 11:00 am
1415 = 2:15 pm
2130 = 9:30 pm
I assume that whole hours such as 1:00 pm are listed as 1300 and 9:00 am as 900.
The integer stores time in military format with hours and minutes only.
If my assumptions are correct then you can do the following:
Create a formula as follows:
if len(totext({Ado.x})) = 4 then TimeSerial(0,(tonumber(rig
if len(totext({Ado.x})) = 3 then TimeSerial(0,(tonumber(rig
if len(totext({Ado.x})) = 2 then TimeSerial(0,{Ado.x},0) else
TimeSerial(0,0,({Ado.x}*36
Put the formula in the report and it should give you what you are looking for. I am sure there are other ways of getting the same results. This is just what came to mind.
GusDarino
ASKER
Your assumptions are correct. And I did mistakenly say 2399 instead of 2359 in my original post. I've accepted bdreed35's answer. Thanks.
NP, I did not refresh my browser before posting. :-) His answer is much better.
GusDarino
GusDarino
What version of Crystal?
mlmcc