Skip to content

Instantly share code, notes, and snippets.

@gboddin

gboddin/time

Created Dec 24, 2014
Embed
What would you like to do?
Some time routine ... I got bored :)
<?php
date_default_timezone_set('Europe/Brussels');
$year = 0;
$month = 1;
$day = 0;
while(true) {
$day++;
$year = str_pad($year,4,"0",STR_PAD_LEFT);
$date = $year.'-'.$month.'-'.$day;
echo $date.' '.date('r',strtotime($date)).PHP_EOL;
switch($month) {
case 4:
case 6:
case 9:
case 11:
if($day == 30) {
$month++;
$day = 0;
}
break;
case 2:
if(($year % 4 != 0 && $day == 28)||($day == 29)) {
$month++;
$day = 0;
}
break;
case 12:
if($day == 31){
$year++;
$month=1;
$day=0;
}
break;
default:
if($day == 31) {
$month++;
$day=0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment