Sunday, September 7, 2014

How to get and format the date in using JQuery

As per previous articles we have seen how to get the data from the web controls using JQuery. Here  we will know how format and add the days to desired date in JQuery.

The below piece of code will get the current date and add days(Here 7days) using Jquery.There is one more functionality also included to get the date in a specific format using Date picker function

<asp:Label id="Label1"  Text="Date" runat="server"/>
<asp:TextBox ID="txtDate" runat="server"/>
<asp:Button id="CalDuration" >Calculate</asp:Button></br />

$("#txtDate").datepicker({ dateFormat: 'mm/dd/yy' }); $('#CalDuration').on('click', function(){ var $date = $('#txtDate').datepicker("getDate"); var resDate = new Date(); resDate.setDate($date.getDate() + 7); alert(resDate.toString());

No comments: