×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

problems about date_and_time
2

problems about date_and_time

problems about date_and_time

(OP)
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

RE: problems about date_and_time

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

RE: problems about date_and_time

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

RE: problems about date_and_time

Is possible do this using the same program struture?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close