Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
System Namespace
DateTime Structure
 DateTime Constructor (Int32, Int32,...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
DateTime Constructor (Int32, Int32, Int32)

Initializes a new instance of the DateTime structure to the specified year, month, and day.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Public Sub New ( _
    year As Integer, _
    month As Integer, _
    day As Integer _
)
Visual Basic (Usage)
Dim year As Integer
Dim month As Integer
Dim day As Integer

Dim instance As New DateTime(year, month, _
    day)
C#
public DateTime(
    int year,
    int month,
    int day
)
Visual C++
public:
DateTime(
    int year, 
    int month, 
    int day
)
JScript
public function DateTime(
    year : int, 
    month : int, 
    day : int
)

Parameters

year
Type: System..::.Int32
The year (1 through 9999).
month
Type: System..::.Int32
The month (1 through 12).
day
Type: System..::.Int32
The day (1 through the number of days in month).
ExceptionCondition
ArgumentOutOfRangeException

year is less than 1 or greater than 9999.

-or-

month is less than 1 or greater than 12.

-or-

day is less than 1 or greater than the number of days in month.

ArgumentException

The specified parameters evaluate to less than MinValue or more than MaxValue.

The time of day for the resulting DateTime is midnight (00:00:00). The Kind property is initialized to DateTimeKind..::.Unspecified.

The following code example demonstrates one of the DateTime constructors.

Visual Basic
      ' Create a new instance of DateTime containing the date 
      ' 7/28/1979 at 10:35:05 PM using the en-US calendar.
      Dim info As New System.Globalization.CultureInfo("en-US", false)
        Dim cal As System.Globalization.Calendar
      cal = info.Calendar

      Dim myDateTime As New System.DateTime(1979, 7, 28, 22, 35, _
                                            5, 15, cal)

      ' Write the DateTime as "Saturday, July 28, 1979 10:35:05 PM".
      System.Console.WriteLine("{0:F}", myDateTime)

C#
            // Create a new instance of DateTime containing the date 
            // 7/28/1979 at 10:35:05 PM using the en-US calendar.
            System.Globalization.CultureInfo info =
                new System.Globalization.CultureInfo("en-US", false);
            
            System.Globalization.Calendar calendar = info.Calendar;
                
            System.DateTime dateTime = 
                new System.DateTime(1979,        // Year
                                    07,            // Month
                                    28,            // Day
                                    22,            // Hour
                                    35,            // Minute
                                    5,            // Second
                                    15,            // Millisecond
                                    calendar    // Calendar
                                    );  

            // Write the DateTime as "Saturday, July 28, 1979 10:35:05 PM".
            System.Console.WriteLine("{0:F}", dateTime);

Visual C++
// Create a new instance of DateTime containing the date 
// 7/28/1979 at 10:35:05 PM using the en-US calendar.
System::Globalization::CultureInfo^ info =
   gcnew System::Globalization::CultureInfo( "en-US",false );

System::Globalization::Calendar^ calendar = info->Calendar;

System::DateTime dateTime =
   System::DateTime( 1979,      // Year
                     07,        // Month
                     28,        // Day
                     22,        // Hour
                     35,        // Minute
                     5,         // Second
                     15,        // Millisecond
                     calendar   // Calendar
                     );

// Write the DateTime as "Saturday, July 28, 1979 10:35:05 PM".
System::Console::WriteLine( "{0:F}", dateTime );

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker