Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Fortran

Idiom #99 Format date YYYY-MM-DD

Assign to the string x the value of the fields (year, month, day) of the date d, in format YYYY-MM-DD.

program p
integer, dimension(8) :: d
character(len=10) :: x
call date_and_time (values=d)
write(x,'(i4.4,"-",i2.2,"-",i2.2)')d(1),d(2),d(3)
print *,'DATE=',x
end program p
with Ada.Calendar.Formatting;
X : constant String :=
    Ada.Calendar.Formatting.Image (D) (1 .. 10);

The Image function returns time as well therefore the slice.

New implementation...