Jabed
Jabed

Reputation: 239

character to integer conversion in fortran

I have a date time value declared as character in this way "1985-01-01-00:00" and I want to extract the year, month and day as integer. I don't know the exact command in FORTRAN language.

Upvotes: 1

Views: 24937

Answers (1)

laxxy
laxxy

Reputation: 1188

For example:

program zz
  character(20) :: ch = "1985-01-01-00:00"
  integer yyyy,mm,dd

  read(ch(1:4),'(i)') yyyy
  read(ch(6:7),'(i)') mm
  read(ch(9:10),'(i)') dd

  write(*,*) yyyy, mm, dd
end program zz

Upvotes: 6

Related Questions