Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 14th, 2003, 08:12 PM
Authorized User
 
Join Date: Jun 2003
Location: London, , United Kingdom.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Time conversions from 24hr to am/pm

Hi people,

A 'hopefully' simple question that I can't seem to find the solution to.

Does anyone know how to format a time that's in 24hr format top simple am or pm format?

eg... 13:00 = 1:00pm

TIA

Blaise.
  #2 (permalink)  
Old July 14th, 2003, 08:34 PM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Don't know if there are any inbuilt functions to do this, but I use this function below.
Can be changed to include seconds if required.

Code:
function ampmTime(InTime)
    dim OutHour, ampm
        if hour(InTime) < 12 then
            OutHour = hour(InTime)
            ampm = "PM"
        end if
        if hour(InTime) = 12 then
            OutHour = hour(InTime)
            ampm = "PM"
        end if
        if hour(InTime) > 12 then
            OutHour = hour(InTime) - 12
            ampm = "PM"
        end if
        ampmTime = OutHour & ":" & minute(Intime) & " " & ampm
end function
  #3 (permalink)  
Old July 14th, 2003, 09:38 PM
Authorized User
 
Join Date: Jun 2003
Location: London, , United Kingdom.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks mate, I really appreciate it.

At first I didn't want to use a function in hope that there would be a VBScript alternative, but alas it seems not, I made a few changes to your function, see below.
Code:
function ampmTime(InTime)
 dim OutHour, ampm, minutes
 if hour(InTime) < 12 then
   OutHour = hour(InTime)
   ampm = "am"
 end if
 if hour(InTime) = 12 then
   OutHour = hour(InTime)
   ampm = "pm"
 end if
 if hour(InTime) > 12 then
   OutHour = hour(InTime) - 12
   ampm = "pm"
 end if
 minutes = minute(intime)
 IF LEN(minutes) < 2 THEN minutes = minutes & "0"
 IF LEN(OutHour) < 2 THEN OutHour = "0" & OutHour
 ampmTime = OutHour & ":" & minutes & ampm
end function


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting "Hooks.pm not found" error jromeirojr Perl 1 May 28th, 2007 06:39 AM
Problem with am/pm in GridView nitinp ASP.NET 2.0 Basics 0 November 4th, 2006 06:11 AM
Converting non 24hr time into number joehoe VB.NET 2002/2003 Basics 1 June 9th, 2005 08:54 AM
Type Conversions nikotromus Access VBA 2 October 7th, 2004 05:30 PM
Formatting a Field Containing a Time to AM/PM taleriana XSLT 2 March 16th, 2004 11:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.