Icon

Just Some Shit I Thought And Wrote.

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

RSS Photography

  • TravellingMan | Semonkong [2] February 6, 2012
    don't know what this procession was about -- was just driving through when I encountered it
    NguJaz
  • Power to TSJS February 6, 2012
    Nuff said
    Jeff Rikhotso
  • Bobby February 6, 2012
    today I missed my dog...
    King-K
  • Bonnie & Clyde February 6, 2012
    This is a little something i'm working on, its called Bonny & Clyde.
    Lebo Shmoove
  • No turning.....back February 6, 2012
    Pride can ruin lives, greed can destroy homes, hate can orphan those relying on others for guidance and support. (A rushed shot through a moving car window somewhere in Jo'Burg)
    Sthe Ngcobo