DateTime add TimeSpan
datetime-add-timespan.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 time
DateTime now = DateTime.Now;
//create a timespan with 2 hours 30 minutes and 50 seconds
TimeSpan ts = new TimeSpan(2,30,50);
//this line added a timespan with current time
DateTime afterAddedTimeSpan = now.Add(ts);
Label1.Text = "current time : " + now.ToLongTimeString();
Label1.Text += "<br /><br />";
Label1.Text += "after added a timespan with current time.........<br />";
Label1.Text += "time span: 2 hours|30 minutes|50 seconds.........<br />";
Label1.Text += afterAddedTimeSpan.ToLongTimeString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - datetime add timespan</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - datetime add timespan
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
Font-Names="Comic Sans MS"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="add timespan to current time"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>

- How to add weeks to a DateTime object
- How to get the AM PM value from a DateTime object
- How to check if a DateTime is between two given dates
- How to check if a DateTime is later than another date
- How to get the first day of a month using a given date
- 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