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.
Description:
In previous articles I explained jQuery redirect to another page after 5 seconds, jQuery iterate through string object, jQuery open videos in modal popup window, jQuery print div with css, jQuery get all selected checkbox values with comma separated values, jQuery Bouncing Menu Example and many articles relating to JavaScript, jQuery, asp.net. Now I will explain how to check date greater than current date using JavaScript / jQuery.
In previous articles I explained jQuery redirect to another page after 5 seconds, jQuery iterate through string object, jQuery open videos in modal popup window, jQuery print div with css, jQuery get all selected checkbox values with comma separated values, jQuery Bouncing Menu Example and many articles relating to JavaScript, jQuery, asp.net. Now I will explain how to 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
|
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. |
|||
|
|||
3 comments :
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
not able check the sample
There is bug in your live demo please check user can enter any date means ex. month as 22
Note: Only a member of this blog may post a comment.