asp.net.ph

DateTime.Add Method

System Namespace   DateTime Structure


Adds the value of a given TimeSpan to the value of this instance.

[ VB ]
<Serializable>
Public Function Add ( _
   ByVal value As TimeSpan _
) As DateTime

[ C# ]
[ Serializable ]
public DateTime Add (
   TimeSpan value
);

[ C++ ]
[ Serializable ]
public: DateTime Add (
   TimeSpan value
);

[ JScript ]
public Serializable
function Add (
   value : TimeSpan
) : DateTime;

Parameters

value
A TimeSpan that contains the interval to add.

Return Value

A DateTime whose value is the sum of the date and time represented by this instance and the time interval represented by value.

Exceptions


Exception Type Condition
ArgumentOutOfRangeException The resulting DateTime is less than MinValue or greater than MaxValue.

Remarks

This method does not change the value of this DateTime. Instead, a new DateTime is returned whose value is the result of this operation.

Example

The below code snippet demonstrates using the Add method. It calculates the day of the week that is 36 days ( 864 hours ) from this moment.

// calculate what day of the week is 36 days from this instant.
System.DateTime today = System.DateTime.Now;
System.TimeSpan duration = new System.TimeSpan ( 36, 0, 0, 0 );
System.DateTime answer = today.Add ( duration );
System.Response.WriteLine ( "{ 0:dddd }", answer );
  C# VB

See Also

DateTime Members   TimeSpan   TimeSpan.Add Skip Navigation Links




Previous page Back to top Next page

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note