current_date_and_time Function

private impure function current_date_and_time() result(datetime)

Retrieves the current date and time and returns it as a string It utilizes the intrinsic date_and_time function to obtain system time information. A string containing the current date and time in the format "YYYY.MM.DD - HH:MM:SS".

Arguments

None

Return Value character(len=21)

Character containing the current date and time


Called by

proc~~current_date_and_time~~CalledByGraph proc~current_date_and_time forbenchmark_default::current_date_and_time proc~init forbenchmark_default::benchmark%init proc~init->proc~current_date_and_time program~demo demo program~demo->proc~init

Source Code

   impure function current_date_and_time() result(datetime)
      !! author: Seyed Ali Ghasemi
      !! Retrieves the current date and time and returns it as a string
      !! It utilizes the intrinsic `date_and_time` function to obtain system time information.
      !! A string containing the current date and time in the format "YYYY.MM.DD - HH:MM:SS".
      !!
      character(21) :: datetime  !! Character containing the current date and time
      character(10) :: date      !! Character containing the current date
      character(8)  :: time      !! Character containing the current time
      integer       :: values(8) !! Array containing the current date and time values
      character(4)  :: year      !! Current year
      character(2)  :: month     !! Current month
      character(2)  :: day       !! Current day
      character(2)  :: hour      !! Current hour
      character(2)  :: minute    !! Current minute
      character(2)  :: second    !! Current second

      call date_and_time(values=values)

      write(year,'(i4)')   values(1)
      write(month,'(i2)')  values(2)
      write(day,'(i2)')    values(3)
      write(hour,'(i2)')   values(5)
      write(minute,'(i2)') values(6)
      write(second,'(i2)') values(7)
      date=year//'.'//month//'.'//day
      time=hour//':'//minute//':'//second
      datetime = date//' - '//time
   end function current_date_and_time