Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add years to todays date in php

Tags:

php

I'm getting a weird date ('01/01/1970 00:00:00) when I run the following code in php:

$now = date('d/m/Y H:i:s', time());
$exp = date('d/m/Y H:i:s', strtotime($now .'+100 years'));
like image 673
Alaa Al Adnani Avatar asked Dec 05 '25 18:12

Alaa Al Adnani


2 Answers

I would try something like this

$date = new DateTime();
$exp = $date->modify('+100 years')->format('d/m/Y H:i:s');
like image 167
Ivan G. Avatar answered Dec 08 '25 08:12

Ivan G.


Try this code :

<?php
$year = date('Y-m-d H:i:s', strtotime('+5 years'));
echo $year;
?>

Output:

2022-06-26 13:29:07

like image 39
RaMeSh Avatar answered Dec 08 '25 09:12

RaMeSh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!