Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Military Time Problem

Reply
Thread Tools

Military Time Problem

 
 
Scott
Guest
Posts: n/a
 
      01-25-2006
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


 
Reply With Quote
 
 
 
 
dNagel
Guest
Posts: n/a
 
      01-25-2006
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
>
>

 
Reply With Quote
 
 
 
 
dNagel
Guest
Posts: n/a
 
      01-25-2006
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.
 
Reply With Quote
 
dNagel
Guest
Posts: n/a
 
      01-25-2006
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.

 
Reply With Quote
 
Scott
Guest
Posts: n/a
 
      01-27-2006
thanks guys.

"dNagel" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
military time in java mrshinton01@gmail.com Java 1 09-22-2007 02:11 AM
Military visit problem. Knut Arvid Keilen Computer Support 6 07-08-2007 06:44 PM
DataFormatString Military Time Phillip Vong ASP .Net 8 12-21-2006 01:45 AM
OE shows military time Robin Computer Support 10 10-26-2004 04:42 PM
Formatting a time field to 24 hour time (Military time) in the Datagrid David Hearn ASP .Net Datagrid Control 1 09-10-2003 02:50 PM



Advertisments