Solved

JavaScript Date functions

Posted on 2011-09-23
4
166 Views
Last Modified: 2012-05-12
This works OK, but not if the two dates are the same:

      // check tdate today or ahead
            fdt = new Date(document.rev.tdate.value);
            dnow = new Date();
            if (fdt.getTime() < dnow.getTime()) {
                  alert("Flight date before today.");
                  return false;
            }      

The format of document.rev.tdate is mm/dd/yy.

Why doesn't this work?            
0
Comment
Question by:Richard Korts
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36588981
replace :  
fdt = new Date(document.rev.tdate.value);

Open in new window

by :  
afdt = document.rev.tdate.value.split("/");
fdt = new Date(2000 + afdt[2], parseInt(afdt[0])-1, afdt[1]); // january = 0, decembre = 11

Open in new window


a good article : http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_484-Can-I-have-a-date.html
don't forget to vote ;-)
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 36589041
@leakim971 I'm glad that you find my article useful.  Thanks for sharing the link!
0
 

Author Comment

by:Richard Korts
ID: 36589131
To leakim971:

Doesn't work. I found out the format was really mm/dd/yyyy, so I changed it to this:

            afdt = document.rev.tdate.value.split("/");
            fdt = new Date(afdt[2], parseInt(afdt[0])-1, afdt[1]); // january = 0, decembre = 11

Still fails for today.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36589245
>@leakim971 I'm glad that you find my article useful.  Thanks for sharing the link!
My pleasure!


>Still fails for today.
Add hour, min and second : fdt = new Date(afdt[2], afdt[0]*1-1, afdt[1],23,59,59); // january = 0, decembre = 11
test page : http://jsfiddle.net/5wuRR/
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question