Codecore Logo
Quick Search
»
Advanced Search »

DateTime Data Type

RSS
Represents an instant in time, typically expressed as a date and time of day.


Constructors

DateTime ( )

Initializes a new DateTime instance to the current date and time.

Syntax:

DateTime ( )

Example:


dt = new DateTime( );

DateTime ( DateTime value )

Initializes a new DateTime instance to the specified value.

Syntax:

DateTime( DateTime value )

Parameters:

value: A DateTime.

Example:


dt1 = new DateTime();
dt2 = new DateTime( dt1 );
// is equivalent to
dt2 = dt1;

DateTime ( Number, Number, Number )

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

Syntax:

DateTime( Number year, Number month, Number day )

Parameters:

year: The year.

month: The month.

day: The numeric day of the month.

Example:


dt = new DateTime( 2008, 21, 1); // results in a date/time of January 21st, 2008  12:00:00 Midnight

DateTime ( Number, Number, Number, Number, Number, Number )

Initializes a new DateTime instance to the specified year, month, day, hour, minute, and second.

Syntax:

DateTime( Number year, Number month, Number day, Number hour, Number minute, Number second )

Parameters:

year: The year.

month: The month.

day: The numeric day of the month.

hour: The hour.

minute: The minute.

second: The seconds.

Example:


dt = new DateTime( 2008, 21, 1, 14, 58, 2);  // results in a date/time of January 21st, 2008  2:58:02 PM

Static Properties

Property NameTypeRead/WriteDescription
NowDateTimeRead OnlyGets a DateTime object that is set to the current date and time, expressed in local time.
TodayDateTimeRead OnlyGets a DateTime object that is set to the current date at midnight.

Instance Properties

Property NameTypeRead/WriteDescription
DayNumberRead OnlyGets the day component of the date.
MonthNumberRead OnlyGets the month component of the date.
YearNumberRead OnlyGets the year component of the date.
HourNumberRead OnlyGets the hour component of the date.
MinuteNumberRead OnlyGets the minute component of the date.
SecondNumberRead OnlyGets the seconds component of the date.
MillisecondNumberRead OnlyGets the milliseconds component of the date.
DayOfWeekNumberRead OnlyGets the day of the week. 0=Sunday, 1=Monday, etc.
DayOfYearNumberRead OnlyGets the day of the year.
IsWeekdayBooleanRead OnlyGets a boolean indicating if the date is a weekday (Monday through Friday).
IsWeekendBooleanRead OnlyGets a boolean indicating if the date is a weekend (Saturday or Sunday).

Instance Methods

AddDays

Adds the specified number of days to the value of this instance.

Syntax:

DateTime AddDays( Number days )

Parameters:

days : A number of whole and fractional days. The value parameter can be negative or positive.

Returns:

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

Example:

dt.AddDays( 1 );

AddHours

Adds the specified number of hours to the value of this instance.

Syntax:

DateTime AddHours( Number hours )

Parameters:

hours : A number of whole and fractional hours. The value parameter can be negative or positive.

Returns:

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

Example:

dt.AddHours( 2 );

AddMilliseconds

Adds the specified number of milliseconds to the value of this instance.

Syntax:

DateTime AddMilliseconds( Number milliseconds )

Parameters:

milliseconds : A number of whole and fractional milliseconds. The value parameter can be negative or positive. Note that this value is rounded to the nearest integer.

Returns:

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

Example:

dt.AddMilliseconds( 500 );

AddMinutes

Adds the specified number of minutes to the value of this instance.

Syntax:

DateTime AddMinutes( Number minutes )

Parameters:

minutes : A number of whole and fractional minutes. The value parameter can be negative or positive.

Returns:

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

Example:

dt.AddMinutes( 15 );

AddMonths

Adds the specified number of months to the value of this instance.

Syntax:

DateTime AddMonths( Number months )

Parameters:

months : A number of months. The months parameter can be negative or positive.

Returns:

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

Example:

dt.AddMonths( 3 );

AddSeconds

Adds the specified number of seconds to the value of this instance.

Syntax:

DateTime AddSeconds( Number seconds )

Parameters:

seconds : A number of whole and fractional seconds. The value parameter can be negative or positive.

Returns:

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

Example:

dt.AddSeconds( 3 );

AddYears

Adds the specified number of years to the value of this instance.

Syntax:

DateTime AddYears( Number years )

Parameters:

years : A number of years. The value parameter can be negative or positive.

Returns:

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

Example:

dt.AddYears( 4 );

ToString ( )

Converts the value of this instance to its equivalent string representation using the computer's current locale format.

Syntax:

String ToString( )

Returns:

A String representation of value of this instance.

Examples:

strToday = new DateTime().ToString( );

ToString ( String )

Converts the value of this instance to its equivalent string representation using the specified format.

Syntax:

String ToString( String format )

Parameters:

format : A format string.

  • Example Format Strings:
    • "d" : 08/17/2000
    • "D" : Thursday, August 17, 2000
    • "f" : Thursday, August 17, 2000 16:32
    • "F" : Thursday, August 17, 2000 16:32:32
    • "g" : 08/17/2000 16:32
    • "G" : 08/17/2000 16:32:32
    • "m" : August 17
    • "r" : Thu, 17 Aug 2000 23:32:32 GMT
    • "s" : 2000-08-17T16:32:32
    • "t" : 16:32
    • "T" : 16:32:32
    • "u" : 2000-08-17 23:32:32Z
    • "U" : Thursday, August 17, 2000 23:32:32
    • "y" : August, 2000
    • "dddd, MMMM dd yyyy" : Thursday, August 17 2000
    • ""ddd, MMM d \"'\"yy" : Thu, Aug 17 '00
    • "dddd, MMMM dd" : Thursday, August 17
    • "M/yy" : 8/00
    • "dd-MM-yy" : 17-08-00

For more format string information visit Date and Time Format Strings

Returns:

A String representation of value of this instance as specified by format.

Examples:

strToday = new DateTime().ToString( "dddd, MMMM dd yyyy" ); // results in "Thursday, January 17 2008"

strTomorrow = new DateTime().AddDays(1).ToString("MM/dd/yyyy");
Privacy Policy | Conditions Of Use

Copyright ©2014 Codecore Technologies, All rights reserved.