Solved

JavaScript Date functions

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…
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…

758 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

20 Experts available now in Live!

Get 1:1 Help Now