Solved

datetime comparison in javascript

Posted on 2009-05-03
3
2,257 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 500 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

829 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