Home

Dates and Times

 

Introduction

A date is a measure of non-spatial units that have elapsed in a set period. To perform this measure, a certain point is set and called midnight. From that point, a number of units are counted until the next corresponding point is reached. Because the light in daily life changes from one midnight unit to the next midnight unit, the sub-point when the light shows up, or starts, is called sunrise. The sub-point when the light diminishes or starts disappearing is called sunset. The midpoint between the sunrise and the sunset is called noon. The first part, from midnight to noon is referred to as AM in US English. The other part is referred to as PM in US English.

The group of units between two midnight points is called a day. The days are counted from 0, 1, and up. A group of seven consecutive days is called a week. The weeks are counted from 1 and up. To make it easy to identify a day, the days of a week are named as Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday. These are referred to as long names. The corresponding short names are Mon, Tue, Wed, Thu, Fri, Sat, and Sun. The day considered as the first of the week depends on the language and/or some other considerations. For example, in US English, Sunday is usually considered the first day of the week.

Most of the time, a group of four weeks is called a month. The months are counted from 1 and up. To make it easy to identify a month, each holds a long name and they are January, February, March, April, May, June, July, August, September, October, November, and December. Their short names are Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, and Dec. Except for the month of February that depends on a factor named Leap Year, the maximum days of each month are January=31, March=31, April=30, May=31, June=30, July=31, August=31, September=30, October=31, November=30, and December=31.

A group of three months is called a trimester. A group of four months is called a quarter. A group of six months is called a semester. A group of twelve months is called a year. The years are counted from 1 and up (some compilers or applications specify when the years start; for example, some applications start their count at 1901 and cannot process years below that numbers; some other applications would not process a year beyond a certain year). The .NET Framework compilers count the years from 0001 to 9999.

In a regular year, the months are counted from 1 to 12. The technique or expression used to identify a particular day during a year is called a date. The days are counted from 1 to 365 or 366 (depending on a factor called a leap year). A date can be the combination of a day, its months, and the year. There are other aspects that can be taken into consideration. We will address them when necessary.

A unit of measure in a day is called a second. The seconds are counted from 0 to 59 or from 0, 1, 2, and so on. In some applications, when precision is particularly important, a second is considered a group of 1000 portions called milliseconds. The milliseconds are counted from 0 to 999.

A group of 60 seconds is called a minute. A group of 60 minutes is called an hour. A group of 24 hours is called a day. The technique or expression used to identify a particular unit of measure during a day is called the time. It can be the combination of the hour, the minute, and the second. Some other aspects may be taken into consideration. We will review them as we move on.

Date Time Value Creation

To represent the dates, computers, applications, and compilers are configured with specific techniques. In Microsoft Windows, to manage dates, the operating system provides a structure named SYSTEMTIME. To manage dates, the .NET Framework provides the DateTime structure. To create a date or a time value, you can first declare DateTime variable. To assist you with initializing the variable, the DateTime structure is equipped with various constructors.

The default constructor allows you to create a date or a time object without specifying its details. This would be done as follows:

using System;

namespace DateAndTime
{
    class Program
    {
        static int Main()
        {
            DateTime tm = new DateTime();

            return 0;
        }
    }
}

After declaring a DateTime variable and initializing it, it holds all necessary pieces of information about its date and its time values.

The Characteristics of a Date Time Value

You can access the information using the variable. The pieces of information are represented by properties of the DateTime structure and they are:

  • Month: The Month property is the numeric value, between 1 and 12, of the month of the variable
  • Day: The Day property is the numeric value of the day in the Month value of the variable. Depending on the month, the value is between 1 and 31. For example, if the variable's value is April 6, 2002, the Day value is 6
  • DayOfWeek: The DayOfWeek property is the name of the Day value of the variable. The name is a member of the DayOfWeek enumeration whose members are Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday. Because the members are listed without a re-definition of their default indexes, the index of Sunday is 0 and the index of Saturday is 6
  • Year: The Year property is the numeric value of the year of the variable
  • DayOfYear: The DayOfYear is the number that represents the ranking day inside of the Year value of the variable. For example, if the variable's value is February 6, 2002, the DayOfYear value is 31 + 6 = 37
  • Date: The Date property is the combination of the Month, the Day, and the Year values of the variable
  • Hour: The Hour is the numeric value of the hour, between 0 and 23, of the time component of the variable
  • Minute: The Minute is the numeric value of the minute inside of the Hour value of the variable. It is a value between 0 and 59 
  • Second: The Second is the numeric value of the second inside of the Minute value of the Hour value. It is a value between 0 and 59
  • Millisecond: The Millisecond is the numeric value of the millisecond inside of the Second value of the Minute part of the Hour section of the variable. It is a value between 0 and 999

The Default Date and Time Values

The default constructor of the DateTime structure initializes the date to January 1st, 0001 and the time at midnight (01:01:01). This is illustrated in the following program:

using System;

namespace DateAndTime
{
    class Program
    {
        static int Main()
        {
            DateTime tm = new DateTime();

            Console.WriteLine("Deault Date and Time: {0}", tm);
            return 0;
        }
    }
}

This would produce:

Deault Date and Time: 1/1/0001 12:00:00 AM
Press any key to continue . . .

This also means that the lowest date and time values that a DateTime object can hold is January 1st, 0001 at 00:00:00. This value is represented by the MinValue constant member of the DateTime structure. The highest date and time that a DateTime object can hold in the structure is called MaxValue and it is set at December 31, 9999.

 

Home Copyright © 2006-2016, FunctionX, Inc. Next