I have a question hw can i ad 18 years to the folowing date

$rowy_geboorte_datum = new DateTime($rowy['geboortedatum']);
$geb_dat_echtgenote = date_format($rowy_geboorte_datum, 'd-m-Y');

$rowy['geboortedatum'] is from a mysql data table and could even before 1902 as example 1820-06-10

thanks in advice John

Recommended Answers

Then your code should work entirely with the datetime class as this isn't limited on date: http://php.net/manual/en/class.datetime.php (I believe you already were, apologies for overlooking the obvious mate!)

$date = …
Jump to Post

All 6 Replies

I now that but as i mention it must work even for dates before 1970 and 1902
the link you give me is for dates after 1970

Then your code should work entirely with the datetime class as this isn't limited on date: http://php.net/manual/en/class.datetime.php (I believe you already were, apologies for overlooking the obvious mate!)

$date = new DateTime('1920-01-01');
$date->modify('+18 years');
echo $date->format('Y-m-d');

//Outputs: 1938-01-01

I believe that will do the job? (Untested!)

Just tested and that works, even back in the year 1066 :)

thanks.
i tried that before too but it did not working and now it is working
Maybee i had a mistype.

Thanks for the help

No worries Johnny :) Post back soon!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.