Home » .NET 4.0 » Add / Substract Date From Current Date

Add / Substract Date From Current Date

Add 14 days to the current date
Current date:    
Date in 2 weeks: 

Markup Page

Current date:
<asp:TextBox ID="TodayDt" runat="server" >
Date in 2 weeks:
<asp:TextBox ID="DaysAhead" runat="server" >


Code Behind

TodayDt.Text = Date.Now.ToShortDateString
DaysAhead.Text = Date.Now.AddDays(-Date.Now.DayOfWeek).AddDays(14).ToShortDateString

Substract 14 days from current date
Current date:     
Date 2 weeks ago: 

Markup Page

Current date:
<asp:TextBox ID="TodayDt" runat="server" >
Date 2 weeks ago:
<asp:TextBox ID="PastDate" runat="server" >


Code Behind

TodayDt.Text = Date.Now.ToShortDateString
PastDate.Text = Date.Now.AddDays(-Date.Now.DayOfWeek).AddDays(-14).ToShortDateString