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

CR 8.5 How to convert AM/PM time to Military Time? 1

Status
Not open for further replies.

gal

Programmer
Mar 5, 2002
25
US
Crystal Reports 8.5: Please provide a formula that converts a Time field containing AM/PM format to Military Time. When I compare two time fields directly, they sort as though they were strings. But, "12:01 AM" should not sort higher than "10:00 PM". Thank you.
 
If the sort is ascending then 12:01 AM SHOULD sort before 10:00 PM
 
Thank you for your response. The Sort is Ascending. I need to convert the time to Military format.
 
This converts the time to a text string but as Military time. Will this work for you?

Code:
totext({?TimeInput},"HH:mm:ss")
 
You use Format Field on the right click menu fo the field.
Choose 'customize'and you can choose 24 hour format.
 
Do you mean converting to 24 clock? So 10 pm shows as 22:00 hours? You can set the format of any time field to 24 clock.
 
This formula works. Thanks for all your efforts.

if Left (totext({history.time}), 2) ="12" and
Right (totext({history.time}), 2) ="AM"
then
"00" + ":" + Mid(totext{history.time}),4,2)
else
if Right (totext({history.time}), 2) ="PM"
then
ToText (CDbl (Left(totext({history.time}),2)) + 12) + ":" +
Mid ( totext({history.time}), 4, 2 )
else
Left (totext({history.time}), 2) + ":" + Mid ( totext({history.time}), 4, 2 )
 
Whole lotta work there for what you have...
now
Create a formula of time({history.time}) (assuming that you have a datetime field)

Riight click the field and select format field->Time-Customize->24 hour and adjust the hour/minutes/seconds as you prefer.

You're creating a string, not a time, so it isn't very useful and it's less efficient.

-k
 
Well I think I understood why setting the format would not work because I believe it only does that at print time. If a comparison was needed that conversion would take place too late. However my little formula gives the same result as Gals solution so my only question is does Crystal 8.5 not allow the syntax I proposed?
 
Uuuuuuhhhhh, a time field sorts correctly, no idea what the issue is here...

If you convert it to a text string, and it has the AM/PM, then of course it will not.

Your formula seems OK, Ridyen, it just wouldn't work for time comparisons.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top