How I may help
LinkedIn Profile Email me!
Call me using Skype client on your machine

Reload this page Date, Time, and Calendar Functions

Your browser is not configured to show Java applets. This would show a clock with the time in California.

This page presents the way various systems handle dates.

May you never have a bad date.

 

Topics this page:

  • Date Classess
  • Getting Timestamps
  • Epochs
  • Time Stamps
  • Date Formatting
  • Month Text to Number
  • Day of Week
  • Leap Years
  • Eras, BC/AD,
  • Julian Dates
  • Work Days
  • Calendar Software
  • Your comments???
  •  

    Site Map List all pages on this site 
    About this site About this site 
    Go to first topic Go to Bottom of this page


    tool time.gov: official US Time

    Set screen Competing Date Formats

      There are several standards followed to format date/time:

      Standard Sample ValuesFormat & Notes
      Email
      ISO8601
      1997-07-16T19:20:30+0100 or
      2004-07-16T19:20:30Z
      Format: "Y-m-d\\TH:i:sO"
      +01:00 means that the time zone is 1 hour ahead of GMT/UTC. Z after the time means GMT/UTC
      W3C
      ATOM
      RSS
      1997-07-16T19:20:30+01:00 or
      2004-07-16T19:20:30Z
      Format: "Y-m-d\\TH:i:sP"
      +01:00 means that the time zone is 1 hour ahead of GMT/UTC. Z after the time means GMT/UTC
      RFC822 Tue, 23 Sep 2003 13:21:00 -07:00 or
      Tue, 23 Sep 2003 13:21:00 GMT
      Format: "D, d M Y H:i:s O"
      -07:00 means that the time zone is 7 hours behind GMT/UTC. GMT means GMT/UTC. There are other written time zone settings.
      UNIX 1121453661on this page Number of seconds since the epoch.
      C Sun Apr 21 15:31:06 2002 -
      Java Sun May 25 19:58:02 PDT 2003 From var now = new Date();
      MS VB 1/19/2003 11:39:00 PM now()on this page
      MS SQL CSV 1998-12-31 23:59:59.999 The format within CSV (text) files input into Microsoft SQL Server databases.
      Whidbey 2003-10-26T14:33:41.1234567Z Contains a Z for time zone. public string StoreDateTime(DateTime value) { return DateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ", CultureInfo.InvariantCulture);


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Principles

      It is best practice to communicate and store timestamps in the GMT/UTC timezone.

      Timestamps obtained by the client from the server are then converted to local time. An example of the coding for ASP.NET is offered in this article: Rendering UTC time in javascript for ASP.NET


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Java Date and Calendar-Related Classes

      The original JDK 1.0 provided the Date class to encapsulate date and time as an object.

      But JDK 1.1 deprecated four of the six Date JDK 1.0 constructors in favor of more international handling of date and time. Only the default constructor that creates a Date object with the current system date and time, and a constructor that creates a Date object from a long value, are not deprecated in JDK 1.2. This was done in favor of new Calendar, DateFormat, GregorianCalendar, SimpleTimeZone, and TimeZone classes to provide more comprehensive and international support of date and time. The DateFormat class of the java.text package was also added to support international date formatting.

      In Java 1.3, the java.util package provide classes for working with dates and calendars. Its Date class encapsulates date and time information and allows date objects to be accessed in a system-independent manner. Here are example code to obtain the system date in milliseconds and display it as a text string:

      import java.util.Date;
      import java.text.SimpleDateFormat;
      ...
      Date currentDatetime = new Date(System.currentTimeMillis());
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
      String myDate = formatter.format(currentDatetime);


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Getting Today's Date

      Set screen Java

      In Java, to return the current date and time:

      private long _timestampIn;
      private long _timestampOut;
      private long _timestampDiff;

      _timestampIn = System.currentTimeMillis();

      // ... work to be timed ...

      _timestampOut = System.currentTimeMillis();
      _timestampDiff = _timestampOut - _timestampIn;
      printInfo("*** Elapsed Time=" + _timestampDiff)/1000
      +" until "+lr.eval_string("")
      +" timestamp"+ java.lang.Long.toString(_timestampOut)
      +" seconds Since TimeStamp "+ java.lang.Long.toString(_timestampIn)
      );

      Set screen Oracle PL/SQL

      In Oracle PL/SQL, to return the current date and time for date x in time zone y as it would be in time zone z:

        NEW_TIME(x,y,z)

      Set screen Microsoft SQL

      The RawDate returned would have a value like "2008-12-31 23.59.58.211".

      SELECT GETDATE() AS RawDate

      Use date formatting functions to extract portions of the MS SQL current date:

      SELECT DATEPART(DayofYear,GETDATE()) AS DayCount
      SELECT DATEPART(dw,GETDATE()) AS DayWeek
      SELECT DATENAME(YEAR,GETDATE()) AS YEAR

      Use date formatting functions to extract portions of the MS SQL current date:

      SELECT DATEDIFF(dd,'2008/12/24',GETDATE()) AS DaysToXmas

      Specify a number after a dot:

      SELECT DATEADD(hh.24,GETDATE()) AS 24HoursFromNow

      The CONVERT() function provides formats (such as 101) used here to create today's date in a text field:

      SELECT CONVERT(CHAR(10),CURRENT_TIMESTAMP,101)

      Format 120 returns the 8 character "12.59.59" time text as a string:

      SELECT substring(Convert(CHAR(19),CURRENT_TIMESTAMP,101),12,8)

      Format 120 returns the 5 character "12.59" time text truncated string:

      SELECT substring(Convert(CHAR(19),CURRENT_TIMESTAMP,101),12,5)

      To create a DateTime field from a formatted date, use:

      SELECT DATEADD(day,DATEDIFF(day,'20081028',CURRENT_TIMESTAMP),'20081028');

      ASP Classic

      In ASP VBScript, to obtain a time stamp:

        date() yields a date such as “1/19/2003”

        now() yields a date and time “1/19/2003 11:39:00 PM”

      More completely:

        function millTimeStamp() {
          var d = new Date();
          return d.getTime()
        }

        timeStart = millTimeStamp();
        // ... something to be timed ...
        timeStop = millTimeStamp()
        elaspedMS = timeStop - timeStart
        Response.write "Elapsed milliseconds=" & elapsedMS & elapsedpretty(elaspedMS)

      Other ASP date functions:

        isdate() returns boolean True or False.

        CDate() returns an expression that has been converted to a Variant of subtype Date. It recognizes date formats according to the locale setting of your system. The correct order of day, month, and year may not be determined if it is provided in a format other than one of the recognized date settings. In addition, a long date format is not recognized if it also contains the day-of-the-week string.

      C# Timers

      .NET has static properties:

        DateTime.Today returns the current date.
        DateTime.Now returns the current time.

      In Excel VBA macros:

        Range("A1") = Now

      The Windows API method GetTickCount() retrieves times in 1ms (millisecond) resolution.

      But the "unmanaged" Win32 API method QueryPerformanceCounter() provides more precise values from high performance timers which runs at the 50,000 (or other) cycles per second LARGE_INTEGER reported by the QueryPerformanceFrequency() call. Daniel Strigl provides sample code to make use of these functions to calculate

        duration = (start - stop) / frequency

      Frequency is driven by microarchitecture (the number of gates per pipepline stage).

      Rational Robot SQA VB Script

      In Rational Robot SQA (vb) script:

      Dim currentdate
      currentdate = CVar(Date)

      PHP:

      Perl

      To get UT in Perl:

      ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
      $t = sprintf "%4d-%02d-%02dT%02d:%02dZ\n",
        ;1900+$year,$mon+1,$mday,$hour,$min;
      print $t;



    Related:

  • Time Zones and Clocks
  • Schedules
  • Historical Dates
  • Data Types
  • Free Training!
  • Tech Support
  • Javascript formatDate function ala PHP

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Calendar Eras

      Monksanother page on this site (are supposed to) focus on Christ. So the Gregorian calendar begins from zero in the "Christian era", around the time Jesus Christ was born.

      A "calendar era" is the fixed starting date for when a year numbering system begins. Examples:

      • "450 BP" means 450 years "Before Present", which is 1500 AD since the "Present" era is the year 1950 AD when radioactive carbon dating tests began.

      • Years on the old Roman calendar are Ab Urbe Condita, meaning "since the founding of the Eternal City" (Rome). Thus
        "25 December 753 AUC" is the beginning of the Gregorian calendar.

      • North Korea calendars today are dated from the year before the birthdate of dictator Kim Il-Soon ("Juche 93" being the year 2004 AD). No, he's not an infant (even though he may act like one sometimes). Many Asian cultures celebrate birthdays from the moment of conception rather than moment of birth.

      • Years on the Hebrew calendar used in Isreal begins from their date of creation (Oct 7, 3761 BC on the Gregorian calendar).

      Set screen BC/AD Era

      The Gregorian calendar used in America and Europe is named after pope Gregory III. Popes speak Latin. So the
      "AD" after Gregorian year numbers signify Anno Domini (Latin for "in the year of our Lord", with Anno meaning "in the year" and Domini meaning "of our Lord".
      "BC" is an abbreviation for the English words "Before Christ". Designations used by other European languages include:

      Language BC AD
      French avJC for avant (for before) Jesus Christ apJC for apres (after) Jesus Christ.
      German vChr or vChrG for vor (before) Christi Geburt (birth) nChr or nChrG for nach (after) Christi Geburt.
      Italian aC for avanti (before) Cristo dC for dopo (after) Cristo.
      Spanish a.C. for avant Christos (before) Christ d.C. for dopo Christos (after) Christ.
      Finnish eKr for ennen Kristuksen syntymaa (before Christ's birth) jKr for jalkeen Kristuksen syntyman (after Christ's birth)
      Swedish fKr for fore (before) Kristus; and eKr for efter (after) Kristus although the Latin "AD" is used in religious texts.
      Dutch vC or vChr for voor (before) Christus AD, anno Domini (the Latin).

      In the 1950's, academics who wanted a secular name (more politically correct to those who deny Christ) invented the word "Common Era" (abbreviated to "CE") for use instead of "AD", with "BCE" (for Before the Common Era) instead of "BC".

      The current Japanese calendar era began at Heisei 1 in early 1989 upon accession of the current Emperor to the throne.

      The Hebrew calendar [W] began October 7 3761 BCE

      Megalomanics (such as Mugabi of Uganda and Kim Il-Sung of North Korea) established their country's calendar to start on their birthdays.

      The traditional Chinese calendar [W] era begins from the reign of the Yellow Emperor on 2698 BC. But since different Western writers also date the event at 2637 BC or 2697 BC, the Gregorian year 2000 coincides with Chinese years 4637, or 4698 as well as the most common 4697.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Julian Dates

      The Julian Date is a day numbering system " a single consecutive number " useful to reconcile different calendars used among different cultures and historical agesanother page on this site

      Originally, the Julian date epoch starts at Noon (12:00), January 1 4713 B.C. -- the beginning of the 7980 year Julian Period ending at 3267 A.D.
      For example, January 1, 1996 is Julian day 2,450,084.

      The Modified Julian Date reduces the number of digits in the day value from 1858 November 17 at 0 hours.
      For example, January 1 1996 is modified julian day 50,083.

      Do not confuse this with the Julian Calendar decreed by Julius Caesar (102-44 BC) in 46 BC. This defined the start of each year on the Kalendae (1st of) January 45 BC with months at fixed lengths. (In 222 BC it was changed back to March until 153 BC).

      To convert from the Julian to a date on the Gregorian calendar,

      • add 10 days to dates from 5 October 1582 JU through 28 February 1700 JU;
      • add 11 days through 28 February 1800 JU;
      • add 12 days through 28 February 1900 JU;
      • add 13 days through 28 February 2100 JU (Not 2000 JU because of the Gregorian leap year in 2000)

      Thus, to get closer to actual seasons, we need to add one more leap year every 1200 years.

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Epochs

      The point in time when a date calendaring system begins counting is called an epoch.

      Microsoft Excel

      Microsoft Excel stores dates as numbers where

      • The integer portion represents the number of whole days since the epoch.
      • The decimal portion represents the fraction of a day since midnight of the epoch (valued at 0.0).
        Each hour, 1/24 of a day, is worth .041666
        . This allows Excel to express dates and times together by changing (in Format, Number) the formula M/D/YYYY HH:MM.
      Excel has two possible epochs:
      TypeEpoch
      On PC software (just as on most other systems) January 1, 1900
      On Mac software (don't get me started on the problems this causes!) January 2, 1904

      Negative values are used to store dates before the epoch.

      A zero value in a PC's date field would be midnight, December 30, 1899.



      To have Excel calculate a datetime stamp value, type:
      =TODAY()

      Idea To avoid possible confusion with Microsoft Excel's differrent epochs, input dates using Excel function:

      =DATE(2006, 4, 5)

      or this function:

      =DATEVALUE("4/5/2006")

      Cells containing these functions appear as numbers when referenced.

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

      Set screen Microsoft SQL

      Microsoft SQL has two data types using two different epochs:
      Data TypeMinimum (Epoch)MaximumPrecision
      datetimeJan 1, 1753
      midnight
      Dec 31, 9999
      23:59:59.997
      (0.003 seconds until midnight)
      To the nearest
      3.33 milliseconds
      smalldatetime Jan 1, 1900
      midnight
      Jun 6, 2079
      23:59
      (1 minute until midnight)
      To the nearest
      minute

      Microsoft SQL does not provide separate variables for date and time because time values are a fraction of the incremental date epoch value.

      Because time values are approximate numerics, queries should search ranges of datetime values. A date without decimals is assumed to be 0.0.

        WHERE TimeVal - CAST(FLOOR(CAST(TimeVal AS float)) AS datetime) > '09:59'
          AND TimeVal - CAST(FLOOR(CAST(TimeVal AS float)) AS datetime) < '10:01'

        WHERE DateVal BETWEEN '2002-02-28' AND '2002-02-28 23:59:59.997'
        WHERE DateVal >= '2002-02-28' AND DateVal < '2002-02-29'

      However, MS-Access users need to use special delimiters for dates:

        WHERE DateVal BETWEEN #2002-02-28# AND #2002-02-28 23:59:59.997#
        WHERE DateVal >= #2002-02-28# AND DateVal < #2002-02-29#

      Idea Bryan Syverson suggests that applications that search for portions of a date/time column (such as for a specific year or hour) would have improved performance if a single date/time column is split into two or more separate columns so that they can each be indexed.

      So, at the time the database is designed, each date/time column should be identified as to whether it will store both dates and times, dates only, or times only.

      Microsoft SQL does not provide separate variables for date and time.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

      Set screen Oracle Epochs

      Data TypeMinimum (Epoch)MaximumPrecision
      DATEJanuary 1, 4712 BC December 31, 9999 AD -

      Oracle's TIMESTAMP datatype accepts a parameter value (fractional_seconds_precision) which defines the fractional part of the SECOND datetime field. It defaults to 6 but has accepted values of 0 to 9.

        TIMESTAMP( fractional_seconds_precision )
        TIMESTAMP( fractional_seconds_precision ) WITH TIME ZONE
        TIMESTAMP( fractional_seconds_precision ) WITH LOCAL TIME ZONE

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

      Set screen UNIX TimeStamps Based on Epochs

      Timestamps from Unix machines and Java programs are based on the number of seconds since the beginning epoch of January 1, 1970 at midnight 00:00:00 GMT (Greenwich Mean Time)another page on this site

      PHP strtotime(), date and mktime at corz and here.

      In C, the date() function uses time_t and clock_t data types defined with the time.h header file. c-time

      Currently, timestamps are either 10 or 13 digits. 13-digit Timestamps (such as 1121453661023) have an additional 3-digit microseconds.

      There is a finite limit on how far into the future a timestamp can be set because type 'time_t' is stored as a long integer data type. On 32-bit machines, the maximum timestamp value is 2,147,483,647, which translates into 1/19/2038 3:19:07AM GMT. So upgrade to 64-bit machines and operating systems if you need to work on dates beyond 2038, when the next "Y2K" crisis will occur.

      Delphi-based executable from Carsten Schmidt

      Network Time Protocol (NTP; RFC2030 for SNTP, Simple NTP) uses a 32-bit count of seconds from 1900-01-01.

      UNIX time calculations do not include the ISO 8601:2000 Leap Seconds, such as at the end of December 2005. The previous one announced by the International Earth Rotation Service, in France was in 1999, adding a "positive" leap second (represented as 23:59:60Z). This needed to align the SI with the Earth's mean rotation slowing down by about 7 ms / year due to the drag of sea-tides.

      Reminder Netscape 7 will cope with cookies set to expire 10-Nov-9999 21:47:44 but will not handle a second higher.

     

    Pop-up in a new window and put this Google Module on your Google homepage

    This uses built-in Javascript function Date() to create a date from the timestamp such as Fri Jul 15 11:54:21 MST 2005. This is then converted from local to UTC time using the method .toGMTString().


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Date Formatting Tokens (Language Cross Reference)

      Item Description PHP C, CGI ASP VBA Oracle Java .NET
      Date Full date string “01/01/01”     %D       .SHORT
      Year 4 digit Year with century (1998 or 2003)   %Y %Y yyyy RRRR,
      IYYY
      yyyy yyyy
      2 digit Year without century (98 or 03)   %y yy RR IY yy yy
      1,3 digit Year (3 for 2003)         I,IYY   y
      Era (BC/AD)         BC,B.C.,
      AD,A.D.
      G gg
      Quarter of Year (1-4) JAN-MAR=1         Q    
      Month Month as a decimal (02) m %m %m MM MM MM MM
      Month without leading zero (2) n %j   M     M
      Abbreviated month name (Feb) M %b, %h %b MMM MON MMM MMM
      Full month name (February) F %B %B MMMM MONTH MMMMM MMMM
      Week Week in Month (1-5)           W
      Day of Weekon this page as integer (1-7)   %w %W   D E
      Abbreviated day name (Fri) D %a %a ddd   EEE ddd
      Weekday Name (Friday) l %A %A dddd DAY   dddd
      ISO Week of Year (1 - 52)   %U, %W     IW w  
      Day of Week in Month (2nd Wed in May)           F  
      Day Day of the month (03) d %d %d dd DD dd dd
      Day without leading zero (3) j %e   d     d
      Ordinal of day of month (eg st or rd or nd) S   %O        
      Day of Year (1 to 365)   %j %j   DDD D  
      Time 12 hour string (“08:17:59 AM”)   %r       .MEDIUM  
      24 hour string (“23:17:59”)   %T          
      Hour in 24 hour format (24) G %H %H   HH24 k H,HH
      Hour in 12 hour format (03) g %I %h HH HH,HH12 K h,hh
      Minute of hour as an integer (01) i %M %N mm MI mm m,mm
      Minute as optional if minute <> 0     %n        
      Second in minute (55) s %S %S   SS ss ss
      Second in minute with no leading zero (5)   %S %S   SS ss s
      MicroSeconds within seconds (600)           SSS fff
      AM/PM Indicator (PM)on this page a
      A
      %p %P AM AM,A.M.
      PM,P.M.
      aaa tt
      First character of AM/PM designator             t
      Time Zone (PDT, PST, etc.)   %Z       z  
      Time Zone offset from GMT O           z,zz

      In the table here, under the C, CGI column are formatting tokens used by the ANSI C strftime function #config and #timefmt Token Codes.

      The VBA column holds the format option used in Microsoft Word menu Insert > Field... > Date and Time > SaveDate > Options... > Add to Field

      To convert VB into Java format: Sun May 25 19:58:02 PDT 2003

        Format(Now, "ddd MMM dd hh:mm:ss ??? yyyy")
        

      To provide more granular control of date formats than what is generated by VB6's

        FormatDateTime( Date, String )
      function, use Ken Schaefer's Date Formatting procedure datefmt.asp

        fncGetDayOrdinal( Now(), string )

      webpage article Obtaining the Dates for Daylight and Standard Time Changes

      The Oracle column lists the format mask codes used in the date_format_mask used in this function:

      TO_CHAR( COLUMN_NAME,'DD-MON-RRRR HH24:MI:SS' )

      The Java column lists the DateFormat codes modifying internationalized functions getDateInstance and getTimeInstance from package java.util.* used by code such as this:

      Date today;
      String dateOut; timeOut;
      DateFormat dateFormatter;
      DateFormat timeFormatter;

      dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, currentLocale);
      timeFormatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, currentLocale);

      today = new Date();
      dateOut = dateFormatter.format(today);
      System.out.println(dateOut + " " + timeOut + " for " currentLocale.toString());

      The list of literals used to designate pattern strings:

      • DEFAULT
      • SHORT
      • MEDIUM
      • LONG
      • FULL

      C# .NET has dates of different pre-set sizes:

        ToShortDateString()
        ToLongDateString()
        ToShortTimeString()
        ToLongTimeString()


    Go to Top of this page.
    Previous topic this page
    Next topic this page

      Set screen VB Date Conversions

      To parse between these two, use Matthew Ferry and Robert Gelb's set of VB date routines
      • InternetTimeToVbLocalTime
      • GetGmtTime (gets GMT time based on your local time),
      • GetTimeHere (gets your local time based on the GMT time),
      • GetTimeDifference (gets the difference in seconds between your local time and the GMT time).

      Set screen C# .NET Date Conversion

      To convert a string into a DateTime object in C# .Net

      using System.DateTime;
      DateTime dateObj = DateTime.Parse("12/30/2005");
      

      Decimal to C Time:

      char *DecToTime(float fTime, char *szTime){
      	int nHrs, nMin, nSec;	
      	fTime *= 3600;
      	nHrs = (int)fTime / 3600;
      	nMin = (int)(fTime - nHrs * 3600) / 60;
      	nSec = (int)(fTime - nHrs * 3600 - nMin * 60);
      	wsprintf(szTime, "%02d.%02d.%02d Hrs.Min.Sec.", nHrs, nMin, nSec);
      	return szTime;
      }

      Set screen MS SQL Date Conversion

      Microsoft SQL uses date formatting codes such as "yy" for year in queries such as:

      SELECT DATENAME(yy,DateOfBirth) AS [Year],

      Extract portions of the MS SQL current dates:

      SELECT DATEPART(DayofYear,GETDATE()) AS DayCount
      SELECT DATEPART(dw,GETDATE()) AS DayWeek




    Go to Top of this page.
    Previous topic this page
    Next topic this page

      Set screen Month Text to Number

      PL/SQL functions use the National Language Set (NLS) date format:

      ADD_MONTHS('15-MAY-2003',3)
      Returns a date 3 months from date in the first parameter.

      LAST_DAY('15-MAY-2003')
      Returns the date of the last day of the month that contains date x.

      MONTHS_BETWEEN('15-MAY-2002','15-MAY-2003')
      Returns a number of months (with decimal value) between dates x and y as produced by x-y.




    Go to Top of this page.
    Previous topic this page
    Next topic this page

      Set screen Day of The Week (DOTW)

      To get something like "Wednesday" Within C#.NET:

       formattedDate = DateTime.Today.DayOfWeek.ToString();
      

      From Winrunner's CSO2LIB Function Generator category csofunctions2:

       get_dow( "12/31/1999", text); 

      In Oracle PL/SQL, to return the name of the next day from date x given:

       NEXT_DAY(x)
      



      Visual Basic constants:

      vbSunday 1 (default) 
      vbMonday 2 
      vbTuesday 3
      vbWednesday 4
      vbThursday 5
      vbFriday 6
      vbSaturday 7
      

      ISO 8601 and UNI 7180-73 standards has the day of week beginning on Monday.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

      Set screen AM/PM Time of Day

      In C#, to spell out AM and PM, create a custom enumeration

      public enum TimeOfDay (
      	Morning = 0;
      	Afternoon = 1;
      	Evening =2;
      }
      
      Then to output the string "Afternoon":

      TimeOfDay time = TimeOfDay.Afternoon;
      Console.WriteLine(time.ToString());
      




    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Leap Years

      To astronomers — who view earth as a celestrial body traveling in space — our planet earth takes 365 days plus a little more than a quarter day to make a complete eliptical orbit (perihelion passage) around the sun. To be precise, the mean "anomalistic" or "solar" year (1994-2000) is (depending on the method of calculation):

        365.259 635 days or 365 days 5 hours 48 minutes 45.2 seconds

      However, since our watches and time clocks (are supposed to) tick along regularly at 24 hours a day, each year the clocks on our wall would be over 5 hours off to the precise time when the spring season actually starts in the "tropical" year — on the vernal equinox when (in the northern hemisphere) night and day are nearly the same length.

      At the first official council of the Christian Churches at Nicaea in 325 AD, the vernal equinox was fixed to a particular date (21 March) each year because Easter celebrations are based on the lunar calendar.

      However, they didn't adjust for celestial mechanics — the "tropical" year being a little slower that the solar year, due to the earth's "precession" (wabbling like a toy top) about its rotational axis (at 0.0003 radians per year), which amount to about a day every 130 years or, to be precise, one part of time in 26,000.

        The earth's axis of rotation slowly and steadily changes at a rate that (if held at its current value) would take some 21,000 years to complete a circuit (around a perpendicular through its orbital plane) with respect to the perihelion-to-aphelion axis.

      In 1985 Lasker defined a tropical year with a formula:

        365.242 189 6698 days - .0000061532597-10T2 + 2.64 x 10-10T3 days,
        where T = (Julian Dateon this page - 2451545 ) / 36525

     


    Go to Top of this page.
    Previous topic this page
    Next topic this page

      Set screen Simon Cassidy believes that the time between Vernal Equinoxes is (for 2000) 365.2424 days or 365 days 6 hours 14 minutes



        "S&H (Stephenson and Houlden's 1986 theory) curve is probably closest to the truth."

      Anyway, eventually people noticed that "spring" actually started in late autumn weather. So in 1582 AD Pope Gregorius XIII declared that the day after 4 October 1582 should be 15 October 1582, eliminating the 10 days to set the Vernal Equinox again at 21 March.

      Since it would be difficult for everyone to adjust their watches an odd amount gradually during the year, we occassionally add a day to the last day in Feburary on a leap year . This happen about every four years, since:

        24 hours / 5 hours ... [from above] = a little under 4

      To adjust for that "little under" part, years divisible by 400 (e.g., 1700, 1800, 1900, 2100) are NOT leap years. With the help of Jesuit astronomer Christopher Clavius (1537-1612) (using earlier proposals of Pitatus and Lilius), this invention (303 years with 365 days and 97 years with 366 days) is what makes the Gregorian calendar we use today have vernal equinoxes slippage of less than one hour in every 300 years (until circa 4000 AD) by achieving a mean year of

        365.24250 days or 365 days 5 hours 49 minutes 12 seconds

      The need for this has been known since the Egyptian calendar, which defined one year with 365.25 mean days consisting of 12 months with a leap year every 4th year — (365*3 + 366)/4.

      The clever part about the Gregorian calendar is that leap years can be calculated by a year that is divisible by 4. This math was defined by a Scythian monk named Dionysius Exiguus under Pope Gregory XIII in 525 AD. Thus the name "Gregorian calendar".

      To be more accurate, the Greek (and now Russian) Orthodox Church early this century made a decision to add one leap-day in 2800 A.D (perhaps a divergance from the Roman Catholic Gregorian Calendar).

      Instead of this, Cassidy proposes the 33 year "Anni Domini" cycle of leap years first proposed by Pope Gregory's Oriental commissioner, the Syrian patriarch Na'amat allah (who in turn cited Omar Khayyam and other Arabic and Persian solar observations). It is calculated with the rule "February will have 29 days whenever the A.D. year-number, reduced modulo 33, is non-zero and divisible by 4."

     


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Work Days

      To get the number of working days between two dates (not including these dates) with this MS-SQL UDF within SQL

        SELECT dbo.GetWorkingDays ('11/13/2000', '12/27/2000')
        

      this page

        CREATE FUNCTION dbo.GetWorkingDays
          ( @StartDate datetime,
            @EndDate datetime 
        	)
        RETURNS INT
        AS
        BEGIN
          DECLARE @WorkDays int, @FirstPart int
          DECLARE @FirstNum int, @TotalDays int
          DECLARE @LastNum int, @LastPart int
          IF (DATEDIFF(day, @StartDate, @EndDate) < 2)
            BEGIN
              RETURN ( 0 )
            END
          SELECT
           @TotalDays = DATEDIFF(day, @StartDate, @EndDate) - 1,
           @FirstPart = CASE DATENAME(weekday, @StartDate)
                         WHEN 'Sunday' THEN 6
                         WHEN 'Monday' THEN 5
                         WHEN 'Tuesday' THEN 4
                         WHEN 'Wednesday' THEN 3
                         WHEN 'Thursday' THEN 2
                         WHEN 'Friday' THEN 1
                         WHEN 'Saturday' THEN 0
                       END,
           @FirstNum = CASE DATENAME(weekday, @StartDate)
                         WHEN 'Sunday' THEN 5
                         WHEN 'Monday' THEN 4
                         WHEN 'Tuesday' THEN 3
                         WHEN 'Wednesday' THEN 2
                         WHEN 'Thursday' THEN 1
                         WHEN 'Friday' THEN 0
                         WHEN 'Saturday' THEN 0
                       END
          IF (@TotalDays < @FirstPart)
             BEGIN
               SELECT @WorkDays = @TotalDays
             END
          ELSE
             BEGIN
               SELECT @WorkDays = (@TotalDays - @FirstPart) / 7
               SELECT @LastPart = (@TotalDays - @FirstPart) % 7
               SELECT @LastNum = CASE
                 WHEN (@LastPart < 7) AND (@LastPart > 0) THEN @LastPart - 1
                 ELSE 0
               END
               SELECT @WorkDays = @WorkDays * 5 + @FirstNum + @LastNum
             END
          RETURN ( @WorkDays )
        END
        GO
        

      This function needs holidays observed for the country and organization, which would ideally be provided by a mechanism available to all, such as a resident table or web service call to a company server.

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Calendar Software

      A website should provide several major calendar services on the internet:

      1. Download Microsoft Outlook Calendar *.vcf file
      2. Apple iCal
      3. Yahoo Calendar
      4. AOL Calendar
      5. Hotmail Calendar
      6. Google Calendar - from a API

      The Calendar class provides support for date conversions that were previously implemented by the Date class. The Calendar class is an abstract class that can be extended to provide conversions for specific calendar systems. The GregorianCalendar subclass supports the predominant calendar system used by many countries.

      The Calendar class provides two constructors-a default parameterless constructor that constructs a calendar with the default TimeZone and Locale objects, and a constructor that allows the TimeZone and Locale objects to be specified. It supplies many constants for accessing days of the week, months of the year, hours, minutes, seconds, milliseconds, and other values.

      The Calendar class provides a number of methods for performing data comparisons, arithmetic, and conversions. The getInstance() method returns a locale-specific calendar that is a GregorianCalendar object, by default.

      GregorianCalendar

      The GregorianCalendar class is a subclass of the Calendar class that supports calendar operations for most of the world. It supports the eras B.C. and A.D. by defining them as class constants. It provides seven constructors that allow GregorianCalendar objects to be created using a combination of different date, time, time zone, and locale values. Its methods override those provided by the Calendar class.

      TimeZone

      The TimeZone class is used to encapsulate the notion of a time zone. It allows you to work in the local time zone, as well as time zones that are selected by a time zone ID. The TimeZone class keeps track of daylight savings time.

      The TimeZone class provides a single, parameterless constructor that creates a TimeZone object corresponding to the local time zone. The TimeZone class does not define any field variables.

      The access methods of TimeZone allow you to get a list of available time zone IDs, retrieve the local time zone (from the operating system), get the local time zone offset (and adjust it for daylight savings time), and create TimeZone objects for other time zone IDs.

      SimpleTimeZone

      The SimpleTimeZone class extends TimeZone to provide support for GregorianCalendar objects. It creates SimpleTimeZone objects using the time zone IDs and offsets defined in the TimeZone class. It provides methods for changing the way daylight savings time is calculated.

      DateApp

      The DateApp program illustrates the use of the date-related classes covered in the previous sections. It shows how Date, GregorianCalendar, and TimeZone objects are created and how to use their methods to access date/time information. The DateApp program is presented in Listing 11.10.

      The program creates a Date object and a GregorianCalendar object using the default Date() and GregorianCalendar() constructors. The Date object is assigned to the today variable, and the GregorianCalendar object is assigned to the cal variable. The cal variable is updated with the current date by invoking its setTime() method with the Date object stored in today. The displayDateInfo() method is then invoked to display date and time information about the cal variable.

      The clear() method of the Calendar class is invoked to reset the date of the GregorianCalendar object stored in cal. The set() method is used to set its date to New Year's 2000. There are several versions of the set() method, each of which takes a different set of parameters. The version used in DateApp takes the year, month, and date as parameters. Note that the month value ranges from 0 to 12, where the year and date values begin at 1. The displayDateInfo() method is invoked again to display information about the new calendar date.

      The displayDateInfo() method creates the days, months, and am_pm arrays to define string values corresponding to the days of the week, months of the year, and a.m./p.m. It then prints a line corresponding to date and time values. These values are retrieved using the get() method of the Calendar class and the Calendar constants corresponding to date/time values. The getTimeZone() method of Calendar is invoked to retrieve the local TimeZone object. The getID() method of the TimeZone class is used to retrieve the local time zone ID string.

      The output of the DateApp program follows. When you run the program, you will obviously get a different date for the first part of the program's processing. The following are the results that were displayed when I ran the program:

     

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Related Topics:

  • Clocks
  • Schedules 
  • Win2000 Admin 
  • WinNT4 Install 
  • Free Training!
  • Tech Support
  • Portions ©Copyright 1996-2011 Wilson Mar. All rights reserved. | Privacy Policy |

    Search


    How I may help

    Send a message with your email client program


    Your rating of this page:
    Low High




    Your first name:

    Your family name:

    Your location (city, country):

    Your Email address: 



      Top of Page Go to top of page

    Thank you!