Solved

JavaScript Date functions

Posted on 2011-09-23
4
165 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

840 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