Skip to content

Instantly share code, notes, and snippets.

@froemken
Created July 22, 2016 06:14
Show Gist options
  • Select an option

  • Save froemken/7e731cded0eb543730b3be78ba604caf to your computer and use it in GitHub Desktop.

Select an option

Save froemken/7e731cded0eb543730b3be78ba604caf to your computer and use it in GitHub Desktop.
<?php
// switch this variable to see the difference
$useTimeZone3 = true;
date_default_timezone_set('Europe/Berlin');
if ($useTimeZone3) {
$date = new \DateTime('2016-09-09 00:00:00');
} else {
$date = new \DateTime(date('c', 1473372000));
}
for ($i = 0; $i < 52; $i++) {
$date->modify('+1 week');
echo $date->format('l - d.m.Y - H:i:s');
$ts = $date->format('U');
echo '-' . $ts . '-';
// $ts wird in DB gespeichert
// Anzeige im Frontend holt $ts wieder aus DB
$dateTimeFromDb = new \DateTime(date('c', $ts));
echo $dateTimeFromDb->format('l - d.m.Y - H:i:s');
echo '<br />';
}
echo '<hr />';
$xths = array(
'first' => 1,
'second' => 0,
'third' => 0,
'fourth' => 1,
'fifth' => 0
);
$weekDays = array(
'monday' => 0,
'tuesday' => 0,
'wednesday' => 0,
'thursday' => 0,
'friday' => 1,
'saturday' => 0,
'sunday' => 0
);
$months = array(
1 => 'july',
2 => 'august',
3 => 'september',
4 => 'october',
5 => 'november',
6 => 'december',
);
if ($useTimeZone3) {
$date = new \DateTime('2016-09-09 00:00:00');
} else {
$date = new \DateTime(date('c', 1473372000));
}
foreach ($months as $month) {
foreach ($xths as $xthIndex => $xth) {
foreach ($weekDays as $weekdayIndex => $weekday) {
if ($xth && $weekday) {
// example: 'second wednesday of March 2013'
$modifyString = $xthIndex . ' ' . $weekdayIndex . ' of ' . $month . ' 2016';
$date->modify($modifyString);
echo $date->format('l - d.m.Y - H:i:s');
$ts = $date->format('U');
// $ts wird in DB gespeichert
// Anzeige im Frontend holt $ts wieder aus DB
$dateTimeFromDb = new \DateTime(date('c', $ts));
echo $dateTimeFromDb->format('l - d.m.Y - H:i:s');
echo '<br />';
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment