Et ses formats (pré)définis, tels que :

  • pre-définis dans la classe DateTime
  • utilisables, ceux du format pris en charge par date
$dateTime = new DateTime();
$dateTime->format(DATE_ATOM); // "Y-m-d\TH:i:sP" qui retourne : 2015-01-28T15:12:00+01:00
// ou
$dateTime->format(DateTime::ATOM); // "Y-m-d\TH:i:sP" qui retourne : 2015-01-28T15:12:00+01:00

// manuellement à la française
$dateTime->format('d/m/Y \à H\hi'); // qui retourne : 28/01/2015 à 15h12

Différence entre 2 dates

$dateTimeCurrent = new DateTime();
$dateTimeChanged = new DateTime($row['date_from_mysql']);
$interval = $dateTimeCurrent->diff($dateTimeChanged);

echo $dateTimeCurrent->format(DATE_ATOM);
echo $dateTimeChanged->format(DATE_ATOM);
echo $interval->format('%R%a jours %h heures %i minutes %s secondes');
$interval->format('%R%a jours %h heures %i minutes %s secondes');;

/* 
 2012-04-18T10:21:34+02:00
 2012-03-01T09:50:00+01:00
-48 jours 0 heures 31 minutes 34 secondes

object(DateInterval)[6]
  public 'y' => int 0
  public 'm' => int 1
  public 'd' => int 17
  public 'h' => int 0
  public 'i' => int 31
  public 's' => int 34
  public 'invert' => int 1
  public 'days' => int 48
*/

/*
var_dump($dateTime);
var_dump($dateTime->format( 'T' ));
object(DateTime)[6]
  public 'date' => string '2012-10-27 10:00:00' (length=19)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Paris' (length=12)
string 'CEST' (length=4)
*/