-1

I want determine how much is the past has been of days, months and years from a date identifies. Unfortunately, my server does not support the php v.5.3, it only supported php v.5.2. i have code in php v.5.3, what can use it in php v.5.2: What do i do?

<?php
$new_date = '2010/7/11';
$then = DateTime::createFromFormat("Y/m/d",$new_date);
$diff = $then->diff(new DateTime());
$year_d = $diff->format("%y"); 
$month_d = $diff->format("%m"); 
$day_d = $diff->format("%d");

echo $year_d .' - ' . $month_d .' - ' . $day_d; //OutPut: 2 - 1 - 21

DEMO: http://codepad.viper-7.com/VNM7OX

j0k
  • 22,600
  • 28
  • 79
  • 90
jennifer Jolie
  • 727
  • 6
  • 16
  • 30
  • See this post, the concept is the same: http://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php – ubrog Sep 01 '12 at 15:23
  • oh it's pretty easy. Save last `timestamp` and compare to the current one. – Yang Sep 02 '12 at 11:05

1 Answers1

1

How about converting to Unix time?

$new_date = '7-11-2010';
$diff = time() - strtotime($new_date); //In seconds
//And you can convert with simple operations
JJJ
  • 32,902
  • 20
  • 89
  • 102