| ACADEMIC COMPUTING and COMMUNICATIONS CENTER | |||||||||
| |||||||||||||||||
Getting ISODATE Formatted Output | |||||||||||||||||
| From SAS | |||||||||||||||||
|
SAS stores dates internally as the number of seconds since midnight, January 1, 1960. Dates before then are stored as negative numbers. The built-in variable <???> contains the current date and time in that format, as an integer quantity. (Actually, all quantities in SAS are stored as 64-bit floating-point numbers. This allows for 56 bits of precision, which avoids the 2037 problem that UNIX has with its 32-bit integer.) SAS has several date and time format codes that will print these huge numbers as human-readable dates and times, but it does not have one for ISO format. You can construct a string variable containing the date in ISO format with the following SAS language commands: (Under construction.) |
|||||||||||||||||
| From SPSS | |||||||||||||||||
|
SPSS stores dates internally as the number of seconds since midnight, October 14, 1582, which was the first day of the Gregorian Calendar. The built-in variable $time contains the current date and time in that format, as an integer quantity. (Actually, all quantities in SPSS are stored as 64-bit floating-point numbers. This allows for 56 bits of precision, which avoids the 2037 problem that UNIX has with its 32-bit integer.) SPSS has several date and time format codes that will print these huge numbers as human-readable dates and times, such as DATE11 which is the British English literary style, but it does not have one for ISO format. You can construct a string variable containing the date in ISO format with the following SPSS language commands: /* Assume the date is contained in SPSS variable "dt" */ STRING isodate (A10). COMPUTE isodate = CONCAT(STRING(XDATE.YEAR(dt),N4.0),'-', STRING(XDATE.MONTH(dt),N2.0),'-' STRING(XDATE.MDAY(dt),N2.0)).To read raw data containing dates in ISO date format, first read it into three Scratch Variables, and then use an Aggregation Function to create a regular permanent variable in SPSS date/time internal format. Scratch variables have names beginning with #, and are only temporary work variables that are not saved in the System File. DATA LIST / #yr 1-4 #mo 6-7 #da 9-10. COMPUTE dt = DATE.MDY(#mo,#da,#yr). BEGIN DATA. 1998-06-23 2000-02-29 2001-01-02 END DATA. |
|||||||||||||||||
| From C Programs | |||||||||||||||||
| (Watch this space!) | |||||||||||||||||
| From Fortran Programs | |||||||||||||||||
The Fortran built-in subroutine DATIM returns an eight member integer
array containing the current date and time broken down into individual elements.
The following Fortran code fragment obtains today's date and writes it in ISO
format:
INTEGER DATP(8) CALL DATIM(DATP) WRITE (6,44) DATP(8),DATP(7),DATP(6) 44 FORMAT(1X,I4.4,'-',I2.2,'-',I2.2) |
|||||||||||||||||
| From Perl Programs | |||||||||||||||||
|
Perl's built-in function time returns the number of seconds since Midnight,
January 1, 1970, GMT. It's conversion functions gmttime, localtime
will convert such a quantity to date and time quantities.
To write this time stamp to a file in ISO format: (Under construction.) |
|||||||||||||||||
| From Rexx Programs | |||||||||||||||||
|
This information applies to all versions of Rexx - VM, OS/2, AIX, or Regina. Some
of the newest versions of Rexx contain extensions that make the following unnecessary,
but those extensions should be avoided for the sake of portability.
The Rexx DATE function returns the date in one of a variety of formats depending on the character constant you pass it. The default format, called Normal, is the British English literary format, "23 Jun 1998", reflecting the fact that Rexx's author, Mike Cowlishaw, is an Englishman. Some of Rexx's date formats should be avoided, such as Century, which gives day number within the century and will go to 0 in 2000, or Usa, which is the American mm/dd/yy, with a two-digit year. The Standard format, yyyymmdd, is the best, since it is very close to ISO. All we need to do is add the dashes. This is easily done by: isodate = translate('year-mn-dt',date('S'),'yearmndt')
If you want to do date arithmetic in Rexx, you should use the Base format, which
is the number of days since January 1, 0001. A variety of routines are available
for converting between the different Rexx date formats. Some newer versions of
Rexx, such as CMS 14, contain extensions to the DATE function that can perform
these conversions. More routines are available on The
Rexx Language Homepage.
This page last updated 1998-09-25. Please send comments and reports of broken links to the author: Roger Deschner |
|||||||||||||||||
| Using ISO 8601 Dates | Previous: 2. In Programs | Next: 4. On Personal Computers |
| 2001-12-21 ACCC Documentation |
|