[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

JavaScript Date functions

Posted on 2011-09-23
4
Medium Priority
?
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

649 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