Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

datetime comparison in javascript

Posted on 2009-05-03
3
Medium Priority
?
2,266 Views
Last Modified: 2012-05-06
Dear All,
i have to compare to datetime value using javascript.

Date1:04/05/2009 11:57
Date2: 04/05/2009 12:05

i want to check the Date1 should be greater than date2 . it should compare time

pls help me to solve this.

Regards
0
Comment
Question by:UJayaPrakashRao
  • 2
3 Comments
 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 24292905
0
 
LVL 7

Accepted Solution

by:
Chandan_Gowda earned 2000 total points
ID: 24292918
//Try the below script
//http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_22657643.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<script language="javascript">
function compareDates(yourdate)
{
      var days = 0;
      var difference = 0;

      date1 = new Date(yourdate); // this is our date      
      today = new Date(); //this is the date time now which was "07/02/2007 11:40 AM"
        alert(date1) //just to check input date
        alert(today) //just to check current date
        difference = date1 - today;
          minutes = Math.round(difference/(1000*60)); // compute minutes
        alert(minutes); //generated -2 minutes
      if (minutes<0)
      {
            alert("The time you have chosen has already passed.");
            return false;
      }
      else
            return true;
}
</script>
</head>

<body>
<script language="javascript">
      compareDates("07/02/2007 11:38 AM")
</script>
</body>
</html>
0
 

Author Closing Comment

by:UJayaPrakashRao
ID: 31577458
Requst
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…
Suggested Courses

972 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