What I am trying to achieve is I want to display the first 15 days of each month and then the remaining days after 15 days of the month. This is for my payroll system.
So for example, first I want to get the current year.
$currentYear = date('Y', strtotime($date_now));
Then I will calculate how many days each month for the current year like this and add then insert the month:
for($i=1;$i<=12;$i++) {
$totaldays=cal_days_in_month(CAL_GREGORIAN,$i,$currentYear);
$firstDay = date($i.'-01-'.$currentYear);
$first15 = date($i.'-15-'.$currentYear);
$after15days = date($i.'-16-'.$currentYear);
$lastDay = date($i.'-'.$totaldays.'-'.$currentYear);
echo $firstDay.'<=>'.$first15;
echo '<br/>';
e`cho .$after15days.'<=>'.$lastDay;
}
With the above codes, it works and I get the following results
1-01-2024 <=> 1-15-2024
1-16-2024 <=> 1-31-2024
2-01-2024 <=> 2-15-2024
2-16-2024 <=> 2-29-2024
3-01-2024 <=> 3-15-2024
3-16-2024 <=> 3-31-2024
and so on…
But when I tried to edit my codes so that the month will display in words, it will not work and it will always display ‘January’; Here’s the code I use:
for($i=1;$i<=12;$i++) {
$totaldays=cal_days_in_month(CAL_GREGORIAN,$i,$currentYear);
$firstDay = date($i.'-01-'.$currentYear);
$firstDay = date('F 1, Y', strtotime($firstDay));
$first15 = date($i.'-15-'.$currentYear);
$first15 = date('F 15, Y', strtotime($first15));
$after15days = date($i.'-16-'.$currentYear);
$after15days = date('F 16, Y', strtotime($after15days));
$lastDay = date($i.'-'.$totaldays.'-'.$currentYear);
$lastDay = date('F '.$totaldays.', Y', strtotime($lastDay));
}
I am expecting:
January 1, 2024 <=> January 15, 2024
January 16, 2024 <=> January 31, 2024
February 1, 2024 <=> February 15, 2024
February 16, 2024 <=> February 29, 2024
But instead I get all month January:
January 1, 2024 <=> January 15, 2024
January 16, 2024 <=> January 31, 2024
January 1, 2024 <=> January 15, 2024
January 16, 2024 <=> January 29, 2024