Solved

Time function needs to be 24 hour format

Posted on 2013-01-26
2
307 Views
Last Modified: 2013-01-26
My page here uses the following code to pull out the start and end times from the database for each event.

It's stored in the database fine in 24 hour time format, but I'm currently just getting the first integer for the hour and minute (e.g. '19 0' instead of '19:00').

Here's the part that handles the time:

  <div class="time">
      <div class="hour"><%=hour(rs("ca_starttime"))%></div>
      <div><%=minute(rs("ca_starttime"))%></div>
   </div> 

<div class="time">
      <div class="hour"><%=hour(rs("ca_endtime"))%></div>
      <div><%=minute(rs("ca_endtime"))%></div>
   </div> 

Open in new window


Many thanks.
0
Comment
Question by:UName10
2 Comments
 
LVL 17

Accepted Solution

by:
wobbled earned 500 total points
ID: 38822223
How are the values stored in the database i.e. are you saving the hour and minute in different fields, if so are these fields set as integers rather than nvarchar etc.

If you wish to hold a number value that has a zero at the start you will need to store it as a string otherwise you will find the initial zero(s) are removed.

If you don't wish to change your database tables you could of course just right a small bit of code that checked if the value returned for minutes was only 1 charactor long and if so add a zero to the start of it.

I've quickly hacked a way of doing this below

Dim strMin = rs("ca_endtime")
e.g. If Len(strMin) = 1 Then strMin = "0" & strMin
0
 

Author Comment

by:UName10
ID: 38822241
Hi wobbled - thanks very much.

That's a good solution, I just added the following suggestion:
<%=Right("00" & minute(rs("ca_starttime")), 2)%>

Open in new window


Yours would work too however, so I'll accept that as the solution.

Many thanks.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question