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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Conversion

Status
Not open for further replies.

prcss46

MIS
May 15, 2002
2
US
Currently, I have a report that displays time in military format but it includes seconds like 145098. The field may be six digit long or five if is in the morning live 70202. The last two digits are always the seconds. I tried to turn this number field into a display format but it only works when I have six digits.
This is the formula: ( I am new at this!)

@display
WhilePrintingRecords;
stringVar tempTime := totext({PLINCD.INCALT},0)

@time
picture({@Display time},"xx:xx:xx")

of course it only works on six digits. I have tried other formulas but I haven't found a solution.

I like the time to show in military time but only HH:MM

Please help!

 
When you say you're getting military time, I'm assuming you mean HHMMSS. I'm just a bit thrown by your example 145098 - with the 98 seconds there.

Perhaps it would be helpful for you to even out your string before you apply your formula, so that all your fields are subjected to reformatting.

It looks as if you're switching time into a string in your first formula. So, using the string conversion you've made, try implementing a formula like:

"if length({@your_string_conversion}) = 5 then "0"+{@your_string_conversion}"
 
There may be an easier way, but here's how I would approach it. If you always have a five digit number in the morning and six in the afternoon/evening:

numbervar hrs:=if len({PLINCD.INCALT})=6 then left({PLINCD.INCALT},2) else left({PLINCD.INCALT},1)
numbervar mins:=if len({PLINCD.INCALT})=6 then mid({PLINCD.INCALT},4,2) else mid({PLINCD.INCALT},3,2)
numbervar secs:=right({PLINCD.INCALT},2)

<if you want to keep military time>
totext(hrs),0)+&quot;:&quot;+totext(mins),0)+&quot;:&quot;+totext(secs),0)

<else if you want normal time>
time(hrs,mins,secs)

Hope this helps.
Chris
DFW Crystal User Group
 
The above sample was a typo it should had said 145008. I tried both formulas but I am getting errors. This is my first time using this so it is probably user error.

The first solution from Naith is black when the report runs.

The second solution it gives me a air message that a number currency or boolean or string is expected between the &quot;if len&quot;

My first experience with this stuff and am ready for another job that doesn't use formulas.

Thanks for your help guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top