Wrox Programmer Forums
|
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript 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 May 5th, 2006, 08:56 AM
Authorized User
 
Join Date: Mar 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parsing Time

I have to display time in HH:MM AM/PM format. My date/time values are being pulled from a MS SQL database that is in smalldatetime field format. I need to take a date such as "5/5/2006 7:35:00 AM" and display it as "7:35 AM". I can't seem to find how to parse this or display only the hours, minutes, and AM/PM designator. Any help is appreciated.

Reply With Quote
  #2 (permalink)  
Old May 7th, 2006, 01:41 PM
Authorized User
 
Join Date: Mar 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My application has Origin and Return trips, each with a Departure and Arrival time. Here's what I cam up with:

Created the following include file:

<%
OD = rsOrigin("departuretime")
ODhr = DatePart("h",OD)
ODmin = DatePart("n",OD)

OA = rsOrigin("arrivaltime")
OAhr = DatePart("h",OA)
OAmin = DatePart("n",OA)

RD = rsReturn("departuretime")
RDhr = DatePart("h",RD)
RDmin = DatePart("n",RD)

RA = rsReturn("arrivaltime")
RAhr = DatePart("h",RA)
RAmin = DatePart("n",RA)

'***AM or PM***
if ODhr < 12 then
ODs = "AM"
Else
ODs = "PM"
End if

if OAhr < 12 then
OAs = "AM"
Else
OAs = "PM"
End if

if RDhr < 12 then
RDs = "AM"
Else
RDs = "PM"
End if

if RAhr < 12 then
RAs = "AM"
Else
RAs = "PM"
End if

'***Origin Departure***
select case ODhr
    Case 0,1,2,3,4,5,6,7,8,9
        ODh = "0"&ODhr

    Case 13,14,15,16,17,18,19,20,21,22,23
        ODh = "0"&ODhr-12

    Case 10,11,12
        ODh = ODhr
End select

if ODmin < 10 then
ODm = "0"&ODmin
Else
ODm = ODmin
End if

'***Origin Arrival***
select case OAhr
    Case 0,1,2,3,4,5,6,7,8,9
        OAh = "0"&OAhr

    Case 13,14,15,16,17,18,19,20,21,22,23
        OAh = "0"&OAhr-12

    Case 10,11,12
        OAh = OAhr
End select

if OAmin < 10 then
OAm = "0"&OAmin
Else
OAm = OAmin
End if

'***Return Departure***
select case RDhr
    Case 0,1,2,3,4,5,6,7,8,9
        RDh = "0"&RDhr

    Case 13,14,15,16,17,18,19,20,21,22,23
        RDh = "0"&RDhr-12

    Case 10,11,12
        RDh = RDhr
End select

if RDmin < 10 then
RDm = "0"&RDmin
Else
RDm = RDmin
End if

'***Return Arrival***
select case RAhr
    Case 0,1,2,3,4,5,6,7,8,9
        RAh = "0"&RAhr

    Case 13,14,15,16,17,18,19,20,21,22,23
        RAh = "0"&RAhr-12

    Case 10,11,12
        RAh = RAhr
End select

if RAmin < 10 then
RAm = "0"&RAmin
Else
RAm = RAmin
End if
%>

Here's the formatting used to display the times in the asp pages:
Origin Departure
<%=ODh%>:<%=ODm%>&nbsp;<%=ODs%>

Origin Arrival
<%=OAh%>:<%=OAm%>&nbsp;<%=OAs%>

Return Departure
<%=RDh%>:<%=RDm%>&nbsp;<%=RDs%>

Return Arrival
<%=RAh%>:<%=RAm%>&nbsp;<%=RAs%>



Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
synchronizing pocket pc time with desktop time bobbyrayudu83 C# 1 April 2nd, 2011 04:28 AM
Time Shift time in minus time out lechalas Beginning VB 6 1 August 11th, 2008 01:56 PM
time zone & day light time rajn ASP.NET 1.0 and 1.1 Professional 0 August 7th, 2007 05:02 PM
time in sql server is not real time hertendreef SQL Server 2005 6 April 19th, 2007 07:07 AM
Using xs:time to generate time in desired format krayan001 XSLT 0 June 27th, 2005 04:28 PM





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