I'm trying to build a website with a calendar converted from Gregorian to IFC. The conversion is simple enough, but I'm not savvy enough in PHP to do all the calculations to display today's date.
I've managed to print current month from a working variable, $dayofyear, which counts the days since Jan 1st (manual input), and then displaying current month through this:
$now = time(); // or your date as well
$your_date = strtotime("2020-01-01"); //I'd also love to get this replaced with a string automatically starting from jan 1st of current year so I don't have to update it every year.
$dayofyear = $now - $your_date;
$day = round($dayofyear / (60 * 60 * 24));
$date = round($dayofyear / (7));
if ($day > 0 && $day < 27) {
echo 'January';
}
elseif ($day > 28 && $day < 55) {
echo 'February';
}
elseif ($day > 56 && $day < 83) {
echo 'March';
}
elseif ($day > 84 && $day < 111) {
echo 'April';
}
elseif ($day > 112 && $day < 139) {
echo 'May';
}
elseif ($day > 140 && $day < 168) {
echo 'June';
}
elseif ($day > 169 && $day < 196) {
echo 'Sol';
}
elseif ($day > 197 && $day < 224) {
echo 'July';
}
elseif ($day > 225 && $day < 252) {
echo 'August';
}
elseif ($day > 253 && $day < 280) {
echo 'September';
}
elseif ($day > 281 && $day < 308) {
echo 'October';
}
elseif ($day > 309 && $day < 336) {
echo 'November';
}
elseif ($day > 337 && $day < 365) {
echo 'December';
}
else {
echo '<i>error...</i>';
}
Also, alternatives to this, to make the code shorter would be greatly appreciated. I've been trying to achieve this through javascript, but unsuccessfully...