How to get the difference between two dates in seconds with PHP

1 Answer

0 votes
$date1 = "2023-01-30";
$date2 = "2023-01-31";

// number of seconds since January 1 1970 00:00:00 UTC

$timestamp1 = strtotime($date1);
$timestamp2 = strtotime($date2);

$seconds = $timestamp2 - $timestamp1;

echo $seconds;
 
 
  
  
  
/*
run:
  
86400
  
*/

 



answered Dec 6, 2023 by avibootz

Related questions

...