Solved

datetime comparison in javascript

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Move inline javascript functions to external .js file in asp.net 12 58
Put javascript to get dropdown value 3 34
Boolean 13 51
Drag & Drop Error 5 33
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 implement server side field validation and display customized error messages to the client.
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…

752 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