cancel
Showing results for 
Search instead for 
Did you mean: 

crystal reports convert number to time value

former_member319241
Participant
0 Kudos
4,849

Hi,

I have a field which is stored in numeric format for time.

The field can be 3 or 4 digits field.

I want to display this fields as the time field.

For example,

900    9:00 AM

1000  10:00 AM

1600  16:00 AM

Please reply.Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

abhilash_kumar
Active Contributor

Hi Saurabh,

Try this:

numbervar x := {number_field};

numbervar fin_t := (x/100)*3600;

NumberVar Hours   := Truncate (fin_t/3600);

NumberVar Minutes := Truncate (Remainder (fin_t,3600)/60);

NumberVar Seconds := Remainder (fin_t,60) ;

ctime(hours, minutes, seconds);

-Abhilash

Answers (2)

Answers (2)

Former Member

Hi  Saurabh,


Try the below formula


StringVar sMyTime := ToText({your_numeric_column}, 0, "");

IF Len(sMyTime) = 3 Then

    cTime(sMyTime[1] & ":" & sMyTime[2 to 3] & " " & "AM"

else IF Len(sMyTime) = 4 Then

    cTime(sMyTime[1 to 2] & ":" & sMyTime[3 to 4] & " " & "AM"



--Naga

siwantham
Discoverer

Hi, You can also use this formula to convert the time to a 24-hour format. Please replace the table name and field name with the appropriate values for your specific data.

Left(Replace(ToText({ORCT.DocTime}, 0), ",", ""), Length(ToText({ORCT.DocTime}, 0)) - 3) +':' + Right(ToText({ORCT.DocTime},0),2)

Original Value 14,33.00

Converted value 14:33

 

Thank you

Siwantha Matarage