Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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.
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:56 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.