How to Get the Date and Time

Suppose a FORTRAN program needs to obtain the current date and the time of day. There is an intrinsic subroutine that will do this for us.

The name of the subroutine is Date_and_Time. It needs 4 arguments: Date, Time, Zone and Values, all used for output. How are these declared?

After the call is processed:

It is important here to realize that Date, Time and Zone all provide data as character strings, while Values provides the same data as integer values.

If any of the data is not available for Date, Time or Zone, the result is all blank. If any of the data is not available for Values, the result is a large negative value.


Example of using Date_and_Time

               Program DATETIME
               Implicit None
               Character(8) :: Date
               Character(10) :: Time
               Character(5) :: Zone
               Integer :: Values(8)

               Call Date_and_Time(Date, Time, Zone, Values)

               Print *, 'The date is ', Date
               Print *
               Print *, 'The time is ', Time
               Print *,
               Print *, 'The time zone difference is ', Zone
          100  Format(/, 1X, A, 2X, I4)
               Print 100, 'The year is        ', Values(1)
               Print 100, 'The month is       ', Values(2)
               Print 100, 'The day is         ', Values(3)
               Print 100, 'The time zone is   ', Values(4)
               Print 100, 'The hour is        ', Values(5)
               Print 100, 'The minute is      ', Values(6)
               Print 100, 'The second is      ', Values(7)
               Print 100, 'The millisecond is ', Values(8)

               End Program DATETIME

The output from running this on October 28, 2009 was:

 The date is 20091028

 The time is 141021.307

 The time zone difference is -0500

 The year is          2009

 The month is           10

 The day is             28

 The time zone is     -300

 The hour is            14

 The minute is          10

 The second is          21

 The millisecond is    307