Solved

datetime comparison in javascript

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

778 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