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

Converting Military Times 1

Status
Not open for further replies.

jl8789

MIS
May 22, 2003
293
US
Is there any way to convert this into a time value in Cold Fusion?
1348 into 1:48?

Thanks
 
#timeformat(militarytime,"hh:mm ss")#

And to convert vise versa

#timeformat(regtime,"HH:mm ss")#

notice the case of HH or hh in both.


ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
This isn't working?
<cfoutput>#timeformat(1348,"HH:mm")#</cfoutput>
nor is
<cfoutput>#timeformat(1348,"hh:mm")#</cfoutput>
 
1348 is not a time...

Let's convert it into a time... or try to

Code:
<Cfset datenum=1348>
<Cfoutput>#timeformat(CreateDateTime(year(now()), month(now()), day(now()), left(datenum,2), right(datenum,2), 0),"hh:mm ss tt")#</cfoutput>

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Was in a hurry earlier..

That won't work quite right on 3 digit numbers (948).. Here's the solution...

You'll see the mods in bold.

Code:
<Cfset datenum=1348>
[b]<cfset datenum=numberformat(datenum,"0000")>[/b]

<Cfoutput>
  #timeformat(CreateDateTime(year(now()), month(now()), day(now()), left(datenum,2), right(datenum,2), 0),"hh:mm ss tt")#
</cfoutput>

or

Code:
<Cfset datenum=1348>

<Cfoutput>
  #timeformat(CreateDateTime(year(now()), month(now()), day(now()), left(datenum,[b]len(datenum)-2[/b]), right(datenum,2), 0),"hh:mm ss tt")#
</cfoutput>

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top