Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Convert military time to am/pm?
Old 06-12-2008, 01:39 PM Convert military time to am/pm?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
I have a time in my database that is in military time...sort of, without the colons. It looks like this in the database: 1400, 1430, 1500, etc.

How would I display this as regular am/pm time? Is there a way to convert this using ASP?

Thanks,
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-12-2008, 02:30 PM Re: Convert military time to am/pm?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
If the hour > 12, subtract 12.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-12-2008, 03:15 PM Re: Convert military time to am/pm?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
Okay, the next step then...

How would I insert the colon in the appropriate place?

For example, if the database gives me 1430, I can calculate that 1430 > 1200, then I can subtract 1200. Now I have 230. How do I insert the colon in the appropriate place?

Thanks,
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 06-12-2008, 03:33 PM Re: Convert military time to am/pm?
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
Code:
function military2normal(strMilitary)
  dim r,hours,ampm : r=""
  if len(strMilitary)>0 and isnumeric(strMilitary) then
    hours=cint(left(strMilitary,2))
    if hours<12 then ampm=" AM" else ampm=" PM"
    if hours=0 then hours=12
    if hours>12 then hours=hours-12
    r=hours & ":" & right(strMilitary,2) & ampm
  end if
  military2normal=r
end function
__________________
~nyef

Please login or register to view this content. Registration is FREE

Last edited by nyef; 06-12-2008 at 03:35 PM..
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-12-2008, 08:04 PM Re: Convert military time to am/pm?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
Awesome, this works perfectly! Thanks a bunch!

WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 06-12-2008, 08:37 PM Re: Convert military time to am/pm?
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
NP =)
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Reply     « Reply to Convert military time to am/pm?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17850 seconds with 12 queries