C# DateTimeOffset AddYears

Description

DateTimeOffset AddYears adds a specified number of years to the DateTimeOffset object.

Syntax

DateTimeOffset.AddYears has the following syntax.


public DateTimeOffset AddYears(
  int years
)

Parameters

DateTimeOffset.AddYears has the following parameters.

  • years - A number of years. The number can be negative or positive.

Returns

DateTimeOffset.AddYears method returns An object whose value is the sum of the date and time represented by the current DateTimeOffset object and the number of years represented by years.

Example

The following example displays the latest possible date on which a person must be born in order to legally be issued a driver's license.


using System;/*from   w  ww  .j  ava  2  s.  c o  m*/

public class MainClass{
  public static void Main(String[] argv){  
    DateTimeOffset dateToday = DateTimeOffset.Now;
    DateTimeOffset latestBirthday = dateToday.AddYears(-1);
    Console.WriteLine(latestBirthday);

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version