Jul 8, 2010 0
Getting Week Start And End Date Using PHP
I have been working on a cron to update payment cycles on a payment management system -
I have had to do this before, when I had to get week end and start dates - with the help of google I had a sample script which was about 100 lines long - Today I had to do the same but I lost my script with my old machine - after cracking my head for about 20 minutes on how im going to get this rite I came up with nifty piece of —
<?php
$this_year = date(”Y”);
$num_weeks = date(”W”, mktime(0,0,0,12,31,$this_year));
for ($x=1;$x<=$num_weeks;$x++){
$week_number = ”;
(strlen($x) == 1) ? $week_number = “0$x” : $week_number = $x;
$week_start = date(’Y-m-d’, strtotime(”{$this_year}W{$week_number}”));
$week_end = date(’Y-m-d’, strtotime(”{$this_year}W{$week_number}7″));
echo “$x - $week_start To $week_end
“;
}
?>
Hope y’all find it useful
