Skip to content

Instantly share code, notes, and snippets.

@ozh
Created February 6, 2013 10:03
Show Gist options
  • Save ozh/4721571 to your computer and use it in GitHub Desktop.
Save ozh/4721571 to your computer and use it in GitHub Desktop.
Generate list of all 365 days in PHP (aka strtotime() fun)
<?php
$now = time();
$a_year_later = strtotime('+1 Year', $now);
$all_days = array();
// starting today
$next = strtotime('+1 Day', strtotime('-1 Day', $now));
// increment day till a year has passed
while( 1 ){
if( $next > $a_year_later )
break 1;
$all_days[] = date( 'Y-m-d', $next );
$next = strtotime( '+1 Day', $next );
}
// result
print_r( $all_days );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment