Skip to content

Instantly share code, notes, and snippets.

@chocnut
Created September 4, 2012 03:10
Show Gist options
  • Save chocnut/3616101 to your computer and use it in GitHub Desktop.
Save chocnut/3616101 to your computer and use it in GitHub Desktop.
Recurring dates in PHP
<?php
require_once('When.php');
$_POST['weekly'] = true;
//array('MO','TU','WE','TH','FR','SA','SU')
$repeat_days = $_POST['selected_days'];
$repeat_type = isset($_POST['weekly']) ?: $_POST['monthly'];
//e.g 01/01/2013
$end = $_POST['end_date'];
if($repeat_type == 'monthly') {
$now = new DateTime();
$end = $now->modify('+'. $_POST['no_of_months] .'month');
}
$w = new When();
$w->recur(new DateTime(), $repeat_type)
->until($end)
->byday($repeat_days);
while ($result = $w->next()) {
$dates = $result->format("Y-m-d H:i:s");
}
var_dump($dates);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment