Solved

datetime comparison in javascript

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now