I have two time fields that have time strings in this format: 07:12 PM
. How do I convert them to military time and as a time field so that I use them in formulas?
cDateTime()
can be used to convert a string to a date.
Then you can format it into military time with the Format Field menu. (Select format 13:23
)
If you need military time inside formulas, and can't just format the outcome, you'd best keep it as a string. Crystal will keep auto-formatting it back to the default format when it performs calculations. But you could convert a standard-time-string to a military-time-string with something like:
If ToNumber(Left({yourValue},2) > 12) Then
CSTR(ToNumber(Left({yourValue},2) - 12) & Mid({yourValue},3,3)
Else If Left({yourValue},2) = "12" And Right({yourValue},2) = "AM"
"00" & Mid({yourValue},3,3)
Else
Left({yourValue},5)