Sun Studio 12: Fortran Library Reference

### 1.4.7.1 date_and_time: Get Date and Time

This is a Fortran 95 intrinsic routine, and is Year 2000 safe.

The date_and_time subroutine returns data from the real-time clock and the date. Local time is returned, as well as the difference between local time and Universal Coordinated Time (UTC) (also known as Greenwich Mean Time, GMT).

The date_and_time() subroutine is called by:

 call date_and_time( date, time, zone, values ) date CHARACTER*8 Output Date, in form CCYYMMDD, where CCYY is the four-digit year, MM the two-digit month, and DD the two-digit day of the month. For example: 19980709 time CHARACTER*10 Output The current time, in the form hhmmss.sss, where hh is the hour, mm minutes, and ss.sss seconds and milliseconds. zone CHARACTER*5 Output The time difference with respect to UTC, expressed in hours and minutes, in the form hhmm values INTEGER*4 VALUES(8) Output An integer array of 8 elements described below.

The eight values returned in the INTEGER*4 values array are

 VALUES(1) The year, as a 4-digit integer. For example, 1998. VALUES(2) The month, as an integer from 1 to 12. VALUES(3) The day of the month, as an integer from 1 to 31. VALUES(4) The time difference, in minutes, with respect to UTC. VALUES(5) The hour of the day, as an integer from 1 to 23. VALUES(6) The minutes of the hour, as an integer from 1 to 59. VALUES(7) The seconds of the minute, as an integer from 0 to 60. VALUES(8) The milliseconds of the second, in range 0 to 999.

An example using date_and_time:

 ```demo% cat dtm.f integer date_time(8) character*10 b(3) call date_and_time(b(1), b(2), b(3), date_time) print *,’date_time array values:’ print *,’year=’,date_time(1) print *,’month_of_year=’,date_time(2) print *,’day_of_month=’,date_time(3) print *,’time difference in minutes=’,date_time(4) print *,’hour of day=’,date_time(5) print *,’minutes of hour=’,date_time(6) print *,’seconds of minute=’,date_time(7) print *,’milliseconds of second=’,date_time(8) print *, ’DATE=’,b(1) print *, ’TIME=’,b(2) print *, ’ZONE=’,b(3) end```

When run on a computer in California, USA on February 16, 2000, it generated the following output:

 ``` date_time array values: year= 2000 month_of_year= 2 day_of_month= 16 time difference in minutes= -420 hour of day= 11 minutes of hour= 49 seconds of minute= 29 milliseconds of second= 236 DATE=20000216 TIME=114929.236 ZONE=-0700```