date compare within 90days?

S

soni2926

Hi,
I have a function where i need to check the date passed in is within
90days of today. Could someone help me get this to work, how do i do
the 90 days compare with today?
<script language='javascript'>
function CheckDate(productDate)
{
var dateVar = new Date(productDate);
//alert(dateVar);
var today = new Date();
//alert(today);
alert( today.getDate()-dateVar.getDate() );
}
</script>

I'm subtracting the date, tried timed, but can't figure out what's it
returning.
 
T

Tom de Neef

(e-mail address removed):
I have a function where i need to check the date passed in is within
90days of today. Could someone help me get this to work, how do i do
the 90 days compare with today?
<script language='javascript'>
function CheckDate(productDate)
{
var dateVar = new Date(productDate);
//alert(dateVar);
var today = new Date();
//alert(today);
alert( today.getDate()-dateVar.getDate() );
}
</script>

I'm subtracting the date, tried timed, but can't figure out what's it
returning.

miliseconds ?
divide by 86 400 000 (nr of miliseconds in a day).
Tom
 
R

roamy

for shure you meant a function in this way ?


<script language='javascript'>
function CheckDate(productDate)
{
var dateVar = Date.parse( productDate );
//alert(dateVar);
var today = new Date();
var Nr_of_Days = ( Date.parse( today ) - dateVar ) / 86400000;
alert( Nr_of_Days );
}
</script>
 
J

Jeremy J Starcher

var Nr_of_Days = ( Date.parse( today ) - dateVar ) / 86400000;

This fails to take daylight savings time changes into account.

getDate() +/- 90 is a much better and bullet proof approach.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>, Mon, 14
Apr 2008 18:51:24 said:
var now = new Date(), later = new Date(), before = new Date();

// 90 days from now
later.setDate(now.getDate() + 90);

var now = new Date(), later = new Date(+now), before = new Date(+now);

should be somewhat more efficient and also proof against improbable
nocturnal inconsistency. Using new Date() requires that the OS supplies
the date and time, which is not necessarily held in the form that a date
Object holds; but using new Date(+now) merely requires creation of the
Object and copying a Double. The + is not always necessary; omitting it
in this case should do no actual harm, but wastes machine time in IE.

If started VERY late in the day, before could get tomorrow.

The OP should check the exact intent of "within 90 days"; is the 90th
day allowed?
 
D

D. Stussy

Thomas 'PointedEars' Lahn said:
Tom said:
(e-mail address removed):
[...]
alert( today.getDate()-dateVar.getDate() );
}
</script>

I'm subtracting the date, tried timed, but can't figure out what's it
returning.

miliseconds ?

More or less.
divide by 86 400 000 (nr of miliseconds in a day).

Won't work precisely until they have abolished DST and implementations have
taken that into account.

Why? Both times should be in UTC which disregards DST/Summertime (as it's
called in Europe).
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
, Mon, 14 Apr 2008 17:25:13, Jeremy J Starcher <[email protected]> posted:


This fails to take daylight savings time changes into account.

Perhaps more importantly, it fails to take the time of today into
account. Nr_of_Days describes an integer.

Since today is a Date Object, +today should be better than
Date.parse(today) which will go via a String - slow, and loses the
milliseconds - and, as there is a subtraction, the + is not needed.
 
L

Lee

(e-mail address removed) said:
Hi,
I have a function where i need to check the date passed in is within
90days of today. Could someone help me get this to work, how do i do
the 90 days compare with today?
<script language='javascript'>
function CheckDate(productDate)
{
var dateVar = new Date(productDate);
//alert(dateVar);
var today = new Date();
//alert(today);
alert( today.getDate()-dateVar.getDate() );
}
</script>

I'm subtracting the date, tried timed, but can't figure out what's it
returning.

And none of the available on-line documentation was any help?


--
 
D

Dr J R Stockton

Mon said:
Thomas 'PointedEars' Lahn said:
Tom said:
(e-mail address removed):
[...]
alert( today.getDate()-dateVar.getDate() );
}
</script>

I'm subtracting the date, tried timed, but can't figure out what's it
returning.

miliseconds ?

More or less.
divide by 86 400 000 (nr of miliseconds in a day).

Won't work precisely until they have abolished DST and implementations have
taken that into account.

Why? Both times should be in UTC which disregards DST/Summertime (as it's
called in Europe).

When a difference of 90 days is called for, that in normal circumstances
means calendar days; and those vary in length. Merely dividing the
number of seconds by 86400 is naive.
 
T

Thomas 'PointedEars' Lahn

D. Stussy said:
"Thomas 'PointedEars' Lahn" [...] wrote [...]
Tom said:
(e-mail address removed):
[...]
alert( today.getDate()-dateVar.getDate() );
}
</script>

I'm subtracting the date, tried timed, but can't figure out what's it
returning.
miliseconds ?
More or less.
divide by 86 400 000 (nr of miliseconds in a day).
Won't work precisely until they have abolished DST and implementations have ^^^^^^
taken that into account.

Why? Both times should be in UTC which disregards DST/Summertime (as it's
called in Europe).

But they are not.

Please use ân app that deserves to be called a newsreader for accessing Usenet.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top