ISO 8601 Dates


The International Standard ISO 8601 specifies the numeric representations of date and time. This standard notation helps to avoid confusion in international communication caused by numerous different notations, and increases the portability of computer user interfaces. In addition, these formats have several important advantages for computer usage compared to other traditional date and time notations.

The international standard date notation is YYYY-MM-DD, which is a four-digit year followed by a two-digit month and a two-digit day. The year is based on the usual Gregorian calendar. For example, March 8, 2003 is written as 2003-03-08. The separators are optional, so you could also express the date as 20030308; this is the format returned by CDateToISO. See Listing 8 . Other components of the date format are beyond the scope of this book. The ISO format has several advantages:

  • It's easily comparable and sortable with a string comparison. This is why I prefer this format when appending dates to file names .

  • The ISO format is easily readable and writable by software because no translation to and from month names is required.

  • It's language and locale independent.

  • There is no ambiguity compared to other date formats. For example, in other formats, there's often a question as to whether the month or the day is listed first. (The convention in Europe, for example, would express the fifth day of June in 2003 as 5/6/03, while in the United States-and North and South America, generally -the same date would commonly be expressed as 6/5/03. The opportunity for confusion is great, especially around the time bills are due near the beginning of each month! This is illustrated by the Month and Day row entries shown in Table 4.)

  • The ISO notation is short and has constant length, which makes data entry, processing, and display easier.

  • Using four digits for the year avoids the Y2K problem for the year 2100. We will, of course, still be in trouble 8000 years from now with the Y10K problem.

Listing 8: Convert to and from ISO date format.
start example
 Print CDateToISO("12/30/1899")           '18991230 Print CDateToISO("12/30/1899 06:00:00")  '18991231 Print CDateToISO(Now)                    '20030816 Print CDateFromISO("14320313")           '03/14/1432 Print CDateFromISO("20030313")           '03/13/2003 Print CDateFromISO("18991230")           '00:00:00 Same 12/30/1899 bug 
end example
 

The function CDateFromISO generates a run-time error if the date contains a time component. There are also the standard difficulties with dates around December 30, 1899, in that they aren't distinguishable from a time. The behavior of the function CDateToISO is the same as the function DateValue: If the date is before 12/31/1899 and it contains a time component, the day is off by one.

Bug  

CDateToISO returns an incorrect day for dates prior to 12/31/1899 if they contain a time component.




OpenOffice.org Macros Explained
OpenOffice.org Macros Explained
ISBN: 1930919514
EAN: 2147483647
Year: 2004
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net