Jump to content

PHP years since date script

Go to solution Solved by leodaniel,
1 hour ago, Joveice said:

Hi, I tryed to look for a script that will display years since a date but I couldent find it. is there anywhere I can learn this fast or if someone can point me towards a snippet?

Try this

$now=  new DateTime();

// Insert your Date here!
$date= new DateTime("22.08.2014");

// Get Difference as DateInterval
$difference = $now->diff($date);

// Get The Difference in Years
echo $difference->format("%y");

 

1 hour ago, Joveice said:

Hi, I tryed to look for a script that will display years since a date but I couldent find it. is there anywhere I can learn this fast or if someone can point me towards a snippet?

Try this

$now=  new DateTime();

// Insert your Date here!
$date= new DateTime("22.08.2014");

// Get Difference as DateInterval
$difference = $now->diff($date);

// Get The Difference in Years
echo $difference->format("%y");

 

Business Management Student @ University St. Gallen (Switzerland)

HomeServer: i7 4930k - GTX 1070ti - ASUS Rampage IV Gene - 32Gb Ram

Laptop: MacBook Pro Retina 15" 2018

Operating Systems (Virtualised using VMware): Windows Pro 10, Cent OS 7

Occupation: Software Engineer

Link to post
Share on other sites

2 hours ago, leodaniel said:

Try this


$now=  new DateTime();

// Insert your Date here!
$date= new DateTime("22.08.2014");

// Get Difference as DateInterval
$difference = $now->diff($date);

// Get The Difference in Years
echo $difference->format("%y");

 

Thanks that works :)

Back-end developer, electronics "hacker"

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×