DateTimeRange

Field: const string DateTimeFormat

Represents the format of the date and time in DateTimeRange data (yyyyMMddHHmmss)


Field: static readonly DateTimeRange Default

It is the default value of DateTimeRange. The start time is the smallest Date value. The end time is the biggest Date value

    DateTimeRange.Default; //1/1/1753 12:00 AM - 12/31/9999 11:29 PM

Method: DateTimeRange Parse(String)

Creates and returns the DateTimeRange object with the date and time range data in the string type.

    DateTimeRange dateTimeRange = DateTimeRange.Parse("20170807120000-20170808101500");
Parameter Name Description
dateRangeString string value in the format yyyyMMddHHmmss-yyyyMMddHHmmss to be parse.

Error Type: ArgumentNullException (This error is thrown if the value is set to null.)

Error Type: FormatException (This error is thrown if the start and end date and time in the value are discarded if they do not conform to the DateTimeFormat.)

Error Type: !:RangeException (This error is thrown if the start date and time are greater than the end date and time.)


Constructor(DateTime, DateTime)

A DateTimeRange object is created with the start and end dates and times in the DateTime type.

    DateTimeRange dateTimeRange = new DateTimeRange(new DateTime(2017,8,7,12,0,0), new DateTime(2017,8,8,10,15,0));
Parameter Name Description
start Start date and time in the DateTime type
end End date and time in the DateTime type

Error Type: !:RangeException (This error is thrown if the start date and time are greater than the end date and time)


Property: DateTime Start

Returns the start date and time of the given DateTime type.


Property: DateTime End

Returns the end date and time of the given DateTime type.


Method: bool Contains(DateTime)

The value of type DateTime returns true if the start and end of the data are within the date and time range, and false otherwise.

If the given value is equal to the initial value or the end value, it is accepted within the range.

    new DateTimeRange(new DateTime(2014, 4, 9, 12, 0, 0), new DateTime(2014, 4, 9, 12, 0, 0)).Contains(new DateTime(2014, 4, 9, 12, 0, 0)); //true
    new DateTimeRange(new DateTime(2014, 4, 9, 12, 0, 0), new DateTime(2014, 4, 9, 12, 0, 1)).Contains(new DateTime(2014, 4, 9, 12, 0, 1)); //true
    new DateTimeRange(new DateTime(2014, 4, 9, 12, 0, 0), new DateTime(2014, 4, 9, 12, 0, 1)).Contains(new DateTime(2014, 4, 9, 12, 0, 0)); //true
    new DateTimeRange(new DateTime(2014, 4, 9, 12, 0, 0), new DateTime(2014, 4, 9, 12, 0, 2)).Contains(new DateTime(2014, 4, 9, 12, 0, 1)); //true

    new DateTimeRange(new DateTime(2014, 4, 9, 12, 0, 1), new DateTime(2014, 4, 9, 12, 0, 2)).Contains(new DateTime(2014, 4, 9, 12, 0, 0)); //false
    new DateTimeRange(new DateTime(2014, 4, 9, 12, 0, 0), new DateTime(2014, 4, 9, 12, 0, 1)).Contains(new DateTime(2014, 4, 9, 12, 0, 2)); //false
Parameter Name Description
date The value to be checked for range in the DateTime type.

Method: TimeSpan GetTimeSpan()

Returns TimeSpan as the number of days, hours, minutes, and how many seconds in the start, end, and end date and time range.

    new DateTimeRange(new DateTime(2014, 4, 9, 12, 0, 0), new DateTime(2014, 4, 9, 12, 0, 1)).GetTimeSpan(); //new TimeSpan(0, 0, 0, 1); = 1 second
    new DateTimeRange(new DateTime(2014, 4, 9, 12, 0, 0), new DateTime(2014, 4, 10, 13, 1, 1)).GetTimeSpan(); //new TimeSpan(1,1,1,1); = 1 day, 1 hour, 1 minute, 1 second

Method: string ToString()

The data is returned in the format yyyyMMddHHmmss-yyyyMMddHHmmss and string type.

    new DateTimeRange(new DateTime(2017,8,7,12,0,0), new DateTime(2017,8,8,10,15,0)).ToString(); // "20170807120000-20170808101500"

Method: bool Equals(Object)

Returns true if the given object has the same value as the DateTimeRange object and the data, false otherwise.

Parameter Name Description
obj Object to be compared

Method: bool Equals(DateTimeRange)

Returns true if the given DateTimeRange object has the same value as the data, false otherwise.

Parameter Name Description
other The object of type DateTimeRange to be compared