Link to home
Start Free TrialLog in
Avatar of Bob Butcher
Bob ButcherFlag for United States of America

asked on

Need help with crystal reports xi formula - convert time from military to regular time

I have two fields - that are both numeric - one or appointment start time and one for appointment end time. They are both stored in a numeric field in SQL Server.

What I need to do, in CR XI, is read the following and I have no idea how to create the formula:
1) read in the number - ex. 1315
2) convert it to a string to manipulate it
3) determine the length of the string - if the length is 3, then I only need to go after the first position of the string because it is a single digit - for example - 815 as opposed to 1730
4) if the first two bytes are greater than 12, I need to subtract 12 - in my case of 13, I need to convert to 1, something like 17 would be a 5
5) then I need to put the first two positions together then concatentate with ":" and then the last two positions -

So if my value is 1315 - I want it to read 1:15 PM

Could someone put together a snippet of code to show me how to do this.

It would be a huge help!!!

Thanks in advance.
Avatar of Mike McCracken
Mike McCracken

Try this formula

Time(1315\100,1315 mod 100,0)

If this is a field then

Time({YourTimeField} \ 100, {YourTimeField} mod 100,0)

mlmcc
Avatar of Bob Butcher

ASKER

How would I get a ":" in between the two sections of hours and minutes? So it is 1:15? Does time do that?
I see now after doing it. Is there anyway I can trim it down from say 10:45:00 AM to like 10:45 AM so I am ignoring the seconds?
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks - exactly what I wanted.