Start Time must be before End Time 
Author Message
 Start Time must be before End Time

I need to compare a start time with an end time.

The formats of the times are: 10:00A (or 10:00P)

if I do alert(Date.parse(document.pageDisplayForm.startTime.value) >
Date.parse(document.pageDisplayForm.endTime.value))

I get false everytime. I missing something here. I'm sure it's simple, but I
can't get my brain around it. Can anyone help?

Thanks!



Tue, 04 Oct 2005 22:48:40 GMT  
 Start Time must be before End Time
Bryan wrote on 18 apr 2003 in microsoft.public.scripting.jscript:

Quote:
> I need to compare a start time with an end time.

> The formats of the times are: 10:00A (or 10:00P)

Strange format!

Are you from the States, perhaps ?

<http://www.merlyn.demon.co.uk/datefmts.htm>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)



Tue, 04 Oct 2005 23:00:02 GMT  
 Start Time must be before End Time
Yes, I agree it's a strange format. I didn't pick it, and to change it would
have an impact of epic proportions.

yes.. I'm in (but not from!) the states!


Quote:
> Bryan wrote on 18 apr 2003 in microsoft.public.scripting.jscript:
> > I need to compare a start time with an end time.

> > The formats of the times are: 10:00A (or 10:00P)

> Strange format!

> Are you from the States, perhaps ?

> <http://www.merlyn.demon.co.uk/datefmts.htm>

> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)



Tue, 04 Oct 2005 23:13:24 GMT  
 Start Time must be before End Time
"Bryan" said:

Quote:

>I need to compare a start time with an end time.

>The formats of the times are: 10:00A (or 10:00P)

>if I do alert(Date.parse(document.pageDisplayForm.startTime.value) >
>Date.parse(document.pageDisplayForm.endTime.value))

>I get false everytime. I missing something here. I'm sure it's simple, but I
>can't get my brain around it. Can anyone help?

You seem to be assuming that Date.parse() can understand
any sort of format that you can understand.

Try:
alert(Date.parse("10:00A");

Then try:
alert(Date.parse("Jan 1, 2000 10:00 am"));



Tue, 04 Oct 2005 23:12:40 GMT  
 Start Time must be before End Time
Bryan wrote on 18 apr 2003 in microsoft.public.scripting.jscript:

Quote:
> Yes, I agree it's a strange format. I didn't pick it, and to change it
> would have an impact of epic proportions.

> yes.. I'm in (but not from!) the states!

I ment "writing from" ;-)

I would translate to 24 hour time:

t="10:00A"
// t="8:00P"

if(/^12:\d\dA$/.test(t))
        t=t.replace(/^12:(\d\d)A$/,"12:$1")
else if(/^12:\d\dP$/.test(t))
        t=t.replace(/^12:(\d\d)P$/,"00:$1")
else if(/^\d\d?:\d\dA$/.test(t))
        t=t.replace(/^(\d\d?:\d\d)A$/,"$1")
else if(/^\d\d?:\d\dP$/.test(t))
        t=(t.replace(/^(\d\d?):\d\dP$/,"$1")*1+12)+
                t.replace(/^\d\d?:(\d\d)P$/,"$1")
else
        t="error";

Not tested, just the idea!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)



Wed, 05 Oct 2005 02:40:23 GMT  
 Start Time must be before End Time


at Fri, 18 Apr 2003 10:48:40 :-

Quote:
>I need to compare a start time with an end time.

>The formats of the times are: 10:00A (or 10:00P)

>if I do alert(Date.parse(document.pageDisplayForm.startTime.value) >
>Date.parse(document.pageDisplayForm.endTime.value))

>I get false everytime.

In that case, either something very strange is happening, or you have
not tested enough.

Try transposing the two values, and you should get the opposite result.  

If you don't, then something strange (to you) is happening.

I guess that you do not.  You have that A>B is false and B>A is false.
There is only one obvious explanation : A=B.  Presumably Date.parse(),
which after all is expecting a date, is dissatisfied; for me,
Date.parse('10:00A') returns NaN.  However, this may depend on
localisation.  Remember, it is almost safe to rely on the Americans to
have programmed date/time illogically.

You should have inspected the results of the individual parses; once
something is simplified, it should be easier to understand.

Date.parse('1/1/1 ' + '10:00A')    returns 1901-01-01 11:00:00 UTC
Date.parse('1/1/1 ' + '10:00P')    returns 1901-01-01 07:00:00 UTC
Date.parse('1/1/1 ' + '10:00AM')   returns 1901-01-01 10:00:00 UTC
Date.parse('1/1/1 ' + '10:00PM')   returns 1901-01-01 22:00:00 UTC

Quote:
>I missing something here. I'm sure it's simple, but I
>can't get my brain around it. Can anyone help?

If you can be sure that the formats are always ##:##X, you can move the
letter to the front, use a RegExp to change 12: to 00:, and then compare
the strings directly - if I interpret that foolish format aright.

function rationalise(X) {
  return X.replace(/(.....)(.)/, '$2$1').replace(/12:/, '00:') }

should do it.  The method is independent of browser localisation.

--

  <URL:http://www.jibbering.com/faq/> FAQ for comp.lang.javascript by Jim Ley.
  <URL:http://www.merlyn.demon.co.uk/js-index.htm>   JS maths, dates, sources.
  <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.



Wed, 05 Oct 2005 04:24:21 GMT  
 Start Time must be before End Time


erxnl.net> posted at Fri, 18 Apr 2003 18:40:23 :-

Quote:
>Bryan wrote on 18 apr 2003 in microsoft.public.scripting.jscript:

>> Yes, I agree it's a strange format. I didn't pick it, and to change it
>> would have an impact of epic proportions.

>> yes.. I'm in (but not from!) the states!

>I ment "writing from" ;-)

>I would translate to 24 hour time:

>t="10:00A"
>// t="8:00P"

>if(/^12:\d\dA$/.test(t))
>       t=t.replace(/^12:(\d\d)A$/,"12:$1")
>else if(/^12:\d\dP$/.test(t))
>       t=t.replace(/^12:(\d\d)P$/,"00:$1")
>else if(/^\d\d?:\d\dA$/.test(t))
>       t=t.replace(/^(\d\d?:\d\d)A$/,"$1")
>else if(/^\d\d?:\d\dP$/.test(t))
>       t=(t.replace(/^(\d\d?):\d\dP$/,"$1")*1+12)+
>               t.replace(/^\d\d?:(\d\d)P$/,"$1")
>else
>       t="error";

>Not tested, just the idea!

Such code can be tested rather rapidly if you use something like A LOCAL
COPY OF my js-quick.htm.  With that page open from a previous use, it
took under ten clicks to show that the above works for 10:00A, and then
two keypresses and a click to show that it is nearly right for 8:00P
(missing colon).

In what I posted yesterday, if the hours part may lack a leading zero,
insert   replace(/\b(\d:)/, "0$1").   after X.   ; and pay attention to
the possible case of A & P.  Mixtures of A, AM, A.M. are unimportant
except when testing for equality, in which case include   (.*)   in the
RegExp.

--

  <URL:http://www.jibbering.com/faq/> FAQ for comp.lang.javascript by Jim Ley.
  <URL:http://www.merlyn.demon.co.uk/js-index.htm>   JS maths, dates, sources.
  <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.



Wed, 05 Oct 2005 20:46:33 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. start date/time, end date/time problem

2. Showing the time where I am

3. Regular expression - It should be easy, but I am having a bad time

4. Time function, displaying AM PM

5. time Stamp at end of script

6. Click to start time

7. Application_OnStart() fires every time Interdev starts debugging

8. Times Greek boldface/italic and Times vs Symbol

9. Time & Time Zones

10. time zones and daylight saving time

11. Object Time Out vs. Session Time Out

12. Formatting Time to GMT when current Time Zone not known

 

 
Powered by phpBB® Forum Software