Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 13th, 2003, 01:25 PM
Authorized User
 
Join Date: Jun 2003
Location: , VA, .
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")
}
Reply With Quote
  #2 (permalink)  
Old June 13th, 2003, 02:29 PM
Friend of Wrox
 
Join Date: May 2003
Location: Indianapolis, IN, USA.
Posts: 207
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.
Reply With Quote
  #3 (permalink)  
Old June 16th, 2003, 05:08 AM
Authorized User
 
Join Date: Jun 2003
Location: Madrid, Madrid, Spain.
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")
?
Reply With Quote
  #4 (permalink)  
Old June 16th, 2003, 05:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
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
Reply With Quote
  #5 (permalink)  
Old June 16th, 2003, 08:27 AM
Authorized User
 
Join Date: Jun 2003
Location: , VA, .
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:20 PM.


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