Skip to content

Instantly share code, notes, and snippets.

@dnavarrojr
Last active December 17, 2018 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnavarrojr/a9384db4c211d044247ed3f2eb1f6a00 to your computer and use it in GitHub Desktop.
Save dnavarrojr/a9384db4c211d044247ed3f2eb1f6a00 to your computer and use it in GitHub Desktop.
Recurring Weekly Array
function tscpl_recurring_weekly( $start_date, $dow, $count ) {
$days = array(
'sunday' => 0,
'monday' => 1,
'tuesday' => 2,
'wednesday' => 3,
'thursday' => 4,
'friday' => 5,
'saturday' => 6
);
$start_date = date( 'Y-m-d', strtotime( $start_date ) );
$start_dow = (int) date( 'w', strtotime( $start_date ) );
if ( gettype( $dow ) == 'string' )
$dow = $days[ strtolower( $dow ) ];
// does our start date equal the DOW?
if ( $start_dow < $dow ) {
$start_date = date( 'Y-m-d', strtotime( $start_date . ' +' . ($dow - $start_dow) . ' days' ) );
} elseif ( $start_dow > $dow ) {
$start_date = date( 'Y-m-d', strtotime( $start_date . ' +' . (7 - ( $start_dow - $dow ) ) . ' days' ) );
}
$i = 0;
$dates = array();
while ( $i < $count ) {
$dates[] = date( 'Y-m-d', strtotime( $start_date . ' +' . $i . ' weeks' ) );
$i++;
}
return $dates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment