Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: DoDateTime Help

  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    NW Iowa
    Posts
    185
    Thanks
    9
    Thanked 0 Times in 0 Posts

    DoDateTime Help

    I'm looking to get my Time format to display as:

    8:00 AM or 5:30 PM

    Right now, the closest I can get is:

    08:30 or 17:30

    What kind of a code do I need to get it into the preferred format?

    Thanks,
    Matt

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,951
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Code:
    Function convertTime(ByVal t)
     dim hh, mm, ampm
     if (not isdate(t)) then exit function
     hh = hour(t)
     mm = minute(t)
     ampm = " AM"
     if hh>=12 then ampm=" PM"
     if hh>12 then 
       hh = hh - 12
     elseif hh=0 then 
       hh=12
     end if
     if mm<10 then mm="0"&mm
     convertTime = hh & ":" & mm & ampm
    End Function
    
    response.write "current time: " & convertTime(time()) & "<br>"
    response.write "midnight: " & convertTime("00:00") & "<br>"
    response.write "noon: " & convertTime("12:00") & "<br>"

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That reminds me of JavaScript date manipulation for some reason.

    But it should definitely work! Glenn's code is very reliable.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •