473,395 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Military Time Problem

If I have a datetime sql field with afternoon datetime values like below in
DATETIME VALUE, how can I display the time part in ASP as 1:00 PM, instead
of 13:00 PM as seen in CURRENT RESULTS below?

Currently, I'm getting my CURRENT RESULTS by using the HOUR() function. Is
there a way to display just the time part in "non-Military" time format?
DATETIME VALUE:
2006-01-24 13:30:00.000

CURRENT RESULTS::
13:30 PM

DESIRED RESULTS:
1:30 PM
Jan 25 '06 #1
5 4790
I've worked up an example that procduced the desired result .. it is
_slightly tested_ ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<pre>
You are going to experience problems with this method unless you format your
Date from SQL in an acceptable format ( as presented below ) before it hits
your JS code.

01-24-2006 13:30:00
</pre>

<script>
// this is where you format your date with server side code
// I'm using your hard coded value for now

var someDate= new Date('01-24-2006 13:30:00');

document.write ( '<pre>' + someDate.toString() + '<br />')

with (someDate)
{
document.write ( getHours() % 12 + ':' + getMinutes() +
( parseInt(getHours()) > 12 ? ' PM' : ' AM') + '</pre>')
}

</script>
</body>
</html>

hth,

D.

Scott wrote:
If I have a datetime sql field with afternoon datetime values like below in
DATETIME VALUE, how can I display the time part in ASP as 1:00 PM, instead
of 13:00 PM as seen in CURRENT RESULTS below?

Currently, I'm getting my CURRENT RESULTS by using the HOUR() function. Is
there a way to display just the time part in "non-Military" time format?
DATETIME VALUE:
2006-01-24 13:30:00.000

CURRENT RESULTS::
13:30 PM

DESIRED RESULTS:
1:30 PM

Jan 25 '06 #2
If you do this a lot you might want to consider adding a new prototype to
the Date object...

<script>

Date.prototype.humanTime = function () {
var sDate = new String();
sDate = ( this.getHours() % 12 + ':' + this.getMinutes() + ( parseInt(this.getHours()) > 12 ? ' PM' : ' AM') )
return (sDate.toString())
}
var someDate= new Date('01-24-2006 13:30:00');
document.write ( '<pre>' + someDate.toString() + '<br />')
document.write ( someDate.humanTime() + '<br />')

var sNow = new Date()
document.write ( 'The time is now : ' + sNow.humanTime() )

document.write ( '</pre>' )

</script>

hth,

D.
Jan 25 '06 #3
ok, too much beer tonight...

I blew it on 12am , and 12pm...

replace the prototype with this ...
Date.prototype.humanTime = function () {
var sDate = new String(), sHour = new String(), sAMPM = new String();
sHour = this.getHours() % 12 ;
sAMPM = parseInt(this.getHours()) > 11 ? ' PM' : ' AM';
if (sHour == 0) sHour = 12;
sDate = sHour + ':' + this.getMinutes() + sAMPM;
return (sDate.toString());
}

D.
dNagel wrote:
If you do this a lot you might want to consider adding a new prototype to
the Date object...

<script>

Date.prototype.humanTime = function () {
var sDate = new String();
sDate = ( this.getHours() % 12 + ':' + this.getMinutes() + (
parseInt(this.getHours()) > 12 ? ' PM' : ' AM') )
return (sDate.toString())
}
var someDate= new Date('01-24-2006 13:30:00');
document.write ( '<pre>' + someDate.toString() + '<br />')
document.write ( someDate.humanTime() + '<br />')

var sNow = new Date()
document.write ( 'The time is now : ' + sNow.humanTime() )

document.write ( '</pre>' )

</script>

hth,

D.

Jan 25 '06 #4
"Scott" wrote:
If I have a datetime sql field with afternoon datetime values like
below in DATETIME VALUE, how can I display the time part in ASP as
1:00 PM, instead of 13:00 PM as seen in CURRENT RESULTS below?


You don't mention the SQL flavor, but I would think you could obtain the
desired format in SQL before trying to deal with it:

http://msdn.microsoft.com/library/en...ca-co_2f3o.asp

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jan 25 '06 #5
thanks guys.

"dNagel" <NO***********@NotMail.com> wrote in message
news:uF**************@TK2MSFTNGP15.phx.gbl...
ok, too much beer tonight...

I blew it on 12am , and 12pm...

replace the prototype with this ...
Date.prototype.humanTime = function () {
var sDate = new String(), sHour = new String(), sAMPM = new String();
sHour = this.getHours() % 12 ;
sAMPM = parseInt(this.getHours()) > 11 ? ' PM' : ' AM';
if (sHour == 0) sHour = 12;
sDate = sHour + ':' + this.getMinutes() + sAMPM;
return (sDate.toString());
}

D.
dNagel wrote:
If you do this a lot you might want to consider adding a new prototype to
the Date object...

<script>

Date.prototype.humanTime = function () {
var sDate = new String();
sDate = ( this.getHours() % 12 + ':' + this.getMinutes() + (
parseInt(this.getHours()) > 12 ? ' PM' : ' AM') )
return (sDate.toString())
}
var someDate= new Date('01-24-2006 13:30:00');
document.write ( '<pre>' + someDate.toString() + '<br />')
document.write ( someDate.humanTime() + '<br />')

var sNow = new Date()
document.write ( 'The time is now : ' + sNow.humanTime() )

document.write ( '</pre>' )

</script>

hth,

D.

Jan 28 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Al | last post by:
Hi Is it a function to convert time to and from military time? Thanks
4
by: richardkreidl | last post by:
How would I check to see if the current time(military format) is greater then 07:30AM and the day of the week is Monday-Friday. Pseudo code: If Current_Time > 07:30AM and Current_Day = Monday...
1
by: ApexData | last post by:
Hello Any know how to convert AM/PM Time to 24Hr Time ? Sample Please ! With and without Now(). ThankYou Greg
8
by: Phillip Vong | last post by:
Simple question from a newbie. Using VWD in VB.NET for ASP.NET. I want to format a time value to show in military time only and without the seconds. I know it's not {0:t} or {0:T} but I can not...
3
by: wocosc | last post by:
I have a quick question.. How can get python to take whatever time of day it is, and output it as military time? I already know how to get it to return the specific time.
8
AccessIdiot
by: AccessIdiot | last post by:
Argh! This is driving me crazy. My db users want to be able to enter a string of numbers for hours, minutes, seconds, in military time format (021256 for 2:12:56 a.m. and 152416 for 3:24:16 p.m.)....
4
by: drg | last post by:
My assignment is actually encapsulation which is not the problem -- my program needs to take two military times and calculate the minutes elapsed between the two. I have everything worked out so...
2
by: Renee Zarazinski | last post by:
I have two fields Time-in & Time-out that are in military time. I have to calculate the difference (to get the total amt. of time spent working) then show the time as clock time. I've only been...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.