Solved

JavaScript Date functions

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now