DateTime add 1 month
This is a .net date time related example. in this example we see how to add month(s) in a date time object.
first we create a date time object using built in now function. then add one month to this date time variable.
finally example show the addition result. all process done programmatically by a button click event.
datetime-add-1-month.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//initialize a datetime variable with current date time
DateTime now = DateTime.Now;
//this line added one month with current datetime object.
DateTime after1Month = now.AddMonths(1);
Label1.Text = "now : " + now.ToLongDateString();
Label1.Text += "<br /><br />after added 1 month to now.........<br />";
Label1.Text += after1Month.ToLongDateString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - datetime add 1 month</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - datetime add 1 month
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="add one month to current date time"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>

- How to get the number of days in a given month
- How to create a TimeSpan
- How to get system DateTime
- How to add weeks to a DateTime object
- How to add a TimeSpan to a DateTime object
- How to get the last day of month using a given date
- How to get the month name from month number
- How to get the first day of week
- How to get the integer value of day of week
- How to get two DateTime objects difference in milliseconds