Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

JQuery Check Given Date Greater than Current Date or Today Date JavaScript

Aug 27, 2013
Introduction

Here I will explain how to use jQuery to check given date greater than current date or today date in JavaScript or check date greater than current date using JavaScript / jQuery.


To implement this we need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Check Given Date Time Greater than Current Date time in JavaScript</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
$('#btnConvert').click(function() {
var param1 = new Date();
var ddate = $('#txtdate').val();
var time = $('#txttime').val();
var hours = Number(time.match(/^(\d+)/)[1]);
var minutes = Number(time.match(/:(\d+)/)[1]);
var format = time.match(/\s(.*)$/)[1];
if (format == "PM" && hours < 12) hours = hours + 12;
if (format == "AM" && hours == 12) hours = hours - 12;
var sHours = hours.toString();
var sMinutes = minutes.toString();
if (hours < 10) sHours = "0" + sHours;
if (minutes < 10) sMinutes = "0" + sMinutes;
ddate = ddate + " " + sHours + ":" + sMinutes + ":00";
var date1 = new Date(ddate);
var date2 = new Date();
if (date1 < date2) {
alert('Please Enter Date time Greater than Current Date time');
$('#txtdate').focus();
return false;
}
})
})
</script>
</head>
<body>
<table>
<tr>
<td><b>Enter Date:</b></td>
<td><input type="text" id="txtdate" value="08/27/2013" /></td>
</tr>
<tr>
<td><b>Enter Time:</b></td>
<td><input type="text" id="txttime" value="10:00 PM" /></td>
</tr>
<tr>
<td></td>
<td><input type="button" id="btnConvert" value="Check Date" /></td>
</tr>
</table>
</body>
</html>
For live demo click on below button to check whether given date time greater than current date time or not

Live Demo

Enter Date:
Enter Time:

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

3 comments :

karthik said...

Hi suresh, your doing great job. thanks many times your site helping me to complete my tasks. now i want to know can we able to send sms from asp.net web page using my gsm modem. please help me and give me a solution. thank you once again

chaitu said...

not able check the sample

Unknown said...

There is bug in your live demo please check user can enter any date means ex. month as 22

Give your Valuable Comments

Other Related Posts

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.