- date: documentation ( source)
- str_pad: documentation ( source)
<?php
$ym = date('Y-m-');
$derived_table = '';
for ($d = 1, $end = date('t'); $d <= $end; ++$d) {
$date = $ym . str_pad($d, 2, 0, STR_PAD_LEFT);
if ($d == 1) {
$derived_table .= "SELECT '$date' AS event_date_start";
} else {
$derived_table .= " UNION SELECT '$date'";
}
}
echo $derived_table;