Solved

Time function needs to be 24 hour format

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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 …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now