473,659 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

date compare within 90days?

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='javas cript'>
function CheckDate(produ ctDate)
{
var dateVar = new Date(productDat e);
//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.
Jun 27 '08 #1
11 2706
so******@yahoo. com:
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='javas cript'>
function CheckDate(produ ctDate)
{
var dateVar = new Date(productDat e);
//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
Jun 27 '08 #2
so******@yahoo. com wrote:
I have a function where i need to check the date passed in is within
90days of today.
Parse error. Are you talking about 90 days or about 3 months? Before or
since today?
Could someone help me get this to work, how do i do
the 90 days compare with today?
<script language='javas cript'>
<script type="text/javascript">
function CheckDate(produ ctDate)
{
var dateVar = new Date(productDat e);
//alert(dateVar);
var today = new Date();
//alert(today);
alert( today.getDate()-dateVar.getDate () );
}
</script>

I'm subtracting the date,
Wrong aproach.
tried timed,
Pardon?
but can't figure out what's it returning.
It *is evaluated to* the number of milliseconds between the dates, with
the provision of its being off by -3'600'000 milliseconds (standard to DST)
or +3'600'000 milliseconds (DST to standard) if DST switching occurs in
between. Therefore, subtraction is the wrong approach here.

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

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

// 90 days ago
before.setDate( now.getDate() - 90);

You can compare the set date with any given date then.

If you mean months, use getMonth() and setMonth(), respectively.
HTH

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jun 27 '08 #3
Tom de Neef wrote:
so******@yahoo. com:
>[...]
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.
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Jun 27 '08 #4
for shure you meant a function in this way ?
<script language='javas cript'>
function CheckDate(produ ctDate)
{
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>
Jun 27 '08 #5
On Mon, 14 Apr 2008 10:07:40 -0700, roamy wrote:
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.
Jun 27 '08 #6
In comp.lang.javas cript message <48************ @PointedEars.de >, Mon, 14
Apr 2008 18:51:24, Thomas 'PointedEars' Lahn <Po*********@we b.de>
posted:
>
var now = new Date(), later = new Date(), before = new Date();

// 90 days from now
later.setDate(n ow.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?

--
(c) John Stockton, nr London, UK. ?@merlyn.demon. co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demo n.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jun 27 '08 #7
"Thomas 'PointedEars' Lahn" <Po*********@we b.dewrote in message
news:48******** ******@PointedE ars.de...
Tom de Neef wrote:
so******@yahoo. com:
[...]
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).
Jun 27 '08 #8
Lee
so******@yahoo. com 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='javas cript'>
function CheckDate(produ ctDate)
{
var dateVar = new Date(productDat e);
//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?
--

Jun 27 '08 #9
In comp.lang.javas cript message <Zr************ ****@nlpi061.nb dc.sbc.com
>, Mon, 14 Apr 2008 17:25:13, Jeremy J Starcher <r3***@yahoo.co m>
posted:
>On Mon, 14 Apr 2008 10:07:40 -0700, roamy wrote:
> var Nr_of_Days = ( Date.parse( today ) - dateVar ) / 86400000;

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(toda y) which will go via a String - slow, and loses the
milliseconds - and, as there is a subtraction, the + is not needed.

--
(c) John Stockton, nr London UK. ??*@merlyn.demo n.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name.
Jun 27 '08 #10

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

Similar topics

4
5121
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows for each record, each row accounts for a different type of outcome I'm having trouble with MySQL date comparison. I'm looking for some kind of query that will compare the all date column and only give me the latest date. Then once I have it, ...
9
3204
by: Gleep | last post by:
sorry i didn't explain it correctly before my table is like this example fields: ID name username outcome date1 date2 date3 (etc..) - date15 price1 price2 price3 (etc..) I know that Mysql query order by will compare records on a specific date, but how do i compare multiple fields within the same record. Want to find the latest date within the record..
4
5364
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
7
31822
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the current date. If not, I'd like to display the error message to ValidationSummary. It seems to make sense to me to use CompareValidator but the problem is put the current date into CompareValidator. So, I created a hidden text field in my aspx. ...
7
23057
by: joeyej | last post by:
How do I compare today's date with this string (in my inc file) so that I can set an alert if date choice i.e. May 15, 2006 not at least greater than two days from current date? <option value="May 15, 2006, (Monday), 10am">May 15, 2006, (Monday), 10am Thanks, Joe
1
1283
by: Budd | last post by:
Hi everyone i got a problem on date, it is... 1, i get the date from calendar component 2, compare today and selected date is equal (compare method) 3 count the number of day between this 2 date
7
2768
by: mr.nimz | last post by:
hello, this is antenio. recently i've come to a problem. i got a way through it, somehow, still it left me in a curious state, so i'm posting it here, if i can get an answer from some techy, here is my table structure, Name: Table1
3
19531
by: junchi.tang | last post by:
Hi, I am new to python and are tryint to write a simple program delete log files that are older than 30 days. So I used os.path.getmtime(filepath) and compare it with a date but it does not compile. threshold_time = datetime.date.today() - datetime.timedelta(days=30) mod_time = os.path.getmtime(file_path)
4
1934
by: jmarcrum | last post by:
Hi everyone!! I have a continuous form that allows users to select a record and chnage the DATE that the record is assigned to another DATE within the same year. The button is called "Change plan Date Within 2008." The user can select a particular record, click that button and a new small form appears that displays the current Plan Date and a textbox for entering a new Plan Date. 'If the New Plan Date is earlier than today's date, this...
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8523
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.