Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems about date_and_time 2

Status
Not open for further replies.

NTC0394

Programmer
Jun 19, 2013
21
I am trying use date_and_time to calculate how old someone are but I am having some problems about how
change characters to integers. Please, help me!!
Thank you in advance

PROGRAM how_old
IMPLICIT none
INTEGER, PARAMETER :: m_year = 12
INTEGER :: m_born, year_born , day_born, how_old
INTEGER :: current year, current_month, current_day
***********my problem************************
CHARACTER(8) :: dat
! call current date
CALL date_and_time( DATE=dat )
*********************************************
PRINT *, "Write the day you was born and press ENTER:"
READ *, day_born
PRINT *, "Write the month you was born and press ENTER:"
READ *, m_born
PRINT *, "Write the year you was born and press ENTER:"
READ *, year_born
how_old = ((current_year - year_born)*m_year + current_month - m_born)/m_year
PRINT *, "You are ", how_old," years"
END PROGRAM how_old
 
You just have to read from rhe character string "dat" :

Code:
PROGRAM main
IMPLICIT none
INTEGER, PARAMETER :: m_year = 12
INTEGER :: m_born, year_born , day_born, how_old 
INTEGER :: current_year, current_month, current_day
!***********my problem************************
CHARACTER(8) :: dat
! call current date
CALL date_and_time( DATE=dat ) 
read(dat,'(i4,i2,i2)') current_year,current_month,current_day
!*********************************************
PRINT *, "Write the day you was born and press ENTER:"
READ *, day_born
PRINT *, "Write the month you was born and press ENTER:"
READ *, m_born
PRINT *, "Write the year you was born and press ENTER:"
READ *, year_born
how_old = ((current_year - year_born)*m_year + current_month - m_born)/m_year 
PRINT *, "You are ", how_old," years"
END PROGRAM main
[/code}

François Jacq
 
Great FJacq!
How to do this without using character?
I mean without using the folliwng:

CHARACTER(8) :: dat
read(dat,'(i4,i2,i2)') current_year,current_month,current_day

 
Is possible do this using the same program struture?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top