downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

date_format> <date_default_timezone_set
Last updated: Fri, 12 Mar 2010

view this page in

date_diff

(PHP 5 >= 5.3.0)

date_diffAlias of DateTime::diff

Description

This function is an alias of: DateTime::diff



add a note add a note User Contributed Notes
date_diff
mark at dynom dot nl
02-Jul-2009 07:44
If you simply want to compare two dates, using conditional operators works too:

<?php
$start
= new DateTime('08-06-1995 Europe/Copenhagen'); // DD-MM-YYYY
$end = new DateTime('22-11-1968 Europe/Amsterdam');

if (
$start < $end) {
    echo
"Correct order";
} else {
    echo
"Incorrect order, end date is before the starting date";
}
?>
tom at knapp2meter dot tk
16-Apr-2009 10:06
A simple way to get the time lag (format: <hours>.<one-hundredth of one hour>).

Hier ein einfacher Weg zur Bestimmung der Zeitdifferenz (Format: <Stunden>.<hundertstel Stunde>).

<?php

function GetDeltaTime($dtTime1, $dtTime2)
{
 
$nUXDate1 = strtotime($dtTime1->format("Y-m-d H:i:s"));
 
$nUXDate2 = strtotime($dtTime2->format("Y-m-d H:i:s"));

 
$nUXDelta = $nUXDate1 - $nUXDate2;
 
$strDeltaTime = "" . $nUXDelta/60/60; // sec -> hour
           
 
$nPos = strpos($strDeltaTime, ".");
  if (
nPos !== false)
   
$strDeltaTime = substr($strDeltaTime, 0, $nPos + 3);

  return
$strDeltaTime;
}

?>

date_format> <date_default_timezone_set
Last updated: Fri, 12 Mar 2010
 
 
show source | credits | sitemap | contact | advertising | mirror sites