×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• 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.

# problems about date_and_time2

 Forum Search FAQs Links MVPs

## 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:"
PRINT *, "Write the month you was born and press ENTER:"
PRINT *, "Write the year you was born and press ENTER:"
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 )
!*********************************************
PRINT *, "Write the day you was born and press ENTER:"
PRINT *, "Write the month you was born and press ENTER:"
PRINT *, "Write the year you was born and press ENTER:"
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

### RE: problems about date_and_time

Is possible do this using the same program struture?

### RE: problems about date_and_time

You can always use the values parameter (see http://docs.oracle.com/cd/E19957-01/805-4942/6j4m3...).

#### CODE

integer timestamp(8)
call date_and_time(values=timestamp)
current_year = timestamp(1)
current_month = timestamp(2)
current_day = timestamp(3) 

You might find [link http://en.wikipedia.org/wiki/Zeller's_congruence]Zeller's congruence[/link] interesting.

#### 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.

#### 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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!