Skip to content

Instantly share code, notes, and snippets.

@asha23
Last active May 17, 2018 16:18
Show Gist options
  • Select an option

  • Save asha23/93ff46a9b0430e2ee047246a696f8c38 to your computer and use it in GitHub Desktop.

Select an option

Save asha23/93ff46a9b0430e2ee047246a696f8c38 to your computer and use it in GitHub Desktop.
Convert string to date - Then work out from today how many weeks until the date
// You won't need the string conversion if this is already a date object.
$booking = '18/06/18'; // example string
$date_array = implode('-', array_reverse(explode('/', $booking)));
$now_booking = date('d/m/Y', strtotime($date_array));
$bookDate = DateTime::createFromFormat('d/m/Y', $now_booking);
$waiting = $today->diff($bookDate);
$interval = $waiting->format('%a') / 7;
$weeks = number_format($interval, 1) + 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment