Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 13th, 2003, 01:25 PM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compare Dates in JS

I have a field that is called ExpireDate. The user enters a date in M/D/YYYY format. I want to compare Expiration Date with today's date. If the Expiration date is less or equal to today's date then I want a message to appear that says "Your product is already expired". Please help with the date compare. This is what I have so far:

function CheckExpire()
{
var currdate = new Date()

if (document.form.ExpireDate.value <= currdate) //Need help here
window.open("Your product is already expired")
}
 
Old June 13th, 2003, 02:29 PM
Friend of Wrox
 
Join Date: May 2003
Posts: 202
Thanks: 0
Thanked 1 Time in 1 Post
Default

Change your code around to be like this:
Code:
function CheckExpire()
{
var currdate = new Date()
var userdate = new Date(document.form.ExpireDate.value)

if (userdate <= currdate){
    window.open("Your product is already expired")
}
You should also probably check for a valid entry in the form field. If the field was null, the userdate date object would evaluate to the current date and time, which would cause the code to say the product is expired.

A good book for Javascript is the Javascript Bible

Bruce Luckcuck
Director, Applications & Support Services
Wiley Publishing, Inc.
 
Old June 16th, 2003, 05:08 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

they window.open as product is put will not work.
why you do not use
alert("Your product is already expired")
?
 
Old June 16th, 2003, 05:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

i've also done this for my project....

check www.peno.com.pl/voytech/register.php

see where you type the month and year

the genuine genius
 
Old June 16th, 2003, 08:27 AM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the posts. Making var userdate = new Date(document.form.ExpireDate.value) worked. I was able to compare the dates this way.

Also, I meant to put window.alert (" MESSAGE") not window.open. Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compare two dates lakshmi_annayappa Javascript 1 September 3rd, 2007 08:52 AM
How to use the datediff function to compare dates cesemj VB How-To 0 June 9th, 2006 04:03 PM
How do I compare 2 dates? Lucy Classic ASP Basics 1 May 3rd, 2005 07:24 PM
Compare dates langer123 Classic ASP Basics 2 April 16th, 2005 08:57 AM
Compare dates [problem]... Varg_88 VB Databases Basics 3 August 20th, 2004 09:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.