-1

I have dates in this format: "28.03.2014". So DD-MM-YYYY.

How do I calculate the number of days since this date?

I found another question where the accepted answer was pretty long, and the date was also in another format.

$now = time(); // or your date as well
$your_date = strtotime("2010-01-01");
$datediff = $now - $your_date;
echo floor($datediff/(60*60*24));

Is this still the way to do things, and do I have to reformat my dates to fit into strtotime?

Kristian Rafteseth
  • 2,002
  • 5
  • 27
  • 46
  • `strtotime` will take practically any date format. Try the existing code and see if it works! – slugonamission Nov 14 '14 at 09:38
  • What exactly is "long" about, e.g., this answer: http://stackoverflow.com/a/16177475/476 ? If you have dates in a different format, use `DateTime::createFromFormat('d.m.Y', $date)` instead of `new DateTime($date)`. – deceze Nov 14 '14 at 09:40
  • If it is preetty long, use this :) echo floor((time() - strtotime('28.03.2014')) / (60*60*24) ); – Muhammed Tanriverdi Nov 14 '14 at 09:48

1 Answers1

0

I'm using Carbon in my composer projects for this and similar purposes.

It'd be as easy as this:

$dt = Carbon::parse('2010-01-01');
echo $dt->diffInDays(Carbon::now());
Arda
  • 6,756
  • 3
  • 47
  • 67