Solved

Time function needs to be 24 hour format

Posted on 2013-01-26
2
308 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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