Skip to content

Instantly share code, notes, and snippets.

@jimmycann
Created April 14, 2016 15:04
Show Gist options
  • Save jimmycann/9d767450c23a0d85dbcb77edc3cbda3d to your computer and use it in GitHub Desktop.
Save jimmycann/9d767450c23a0d85dbcb77edc3cbda3d to your computer and use it in GitHub Desktop.
Convert Custom Date with PHP
<?php
$depart = "140117";
$arrive = "arriving on 21 January 2017";
$dep_date = DateTime::createFromFormat('dmy', $depart);
$arr_date = DateTime::createFromFormat('\a\r\r\i\v\i\n\g \o\n d F Y', $arrive);
$date_diff = $dep_date->diff($arr_date);
$dep_date = $dep_date->format('d-m-Y');
$arr_date = $arr_date->format('m/d/Y');
echo "The difference between ". $dep_date ." and ". $arr_date ." is ". $date_diff->d ." days.";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment