Hello,

Have a bit of a odd-one here: I'm attempting to determine / return a date (ex: 10/28/2002) based off of these parameters:

  • year ( 2002)
  • week number (1-52)
  • day name (Saturday, Sunday, etc.)

..so I'm wondering which date funtions I need to cludge together to get this to work, any suggestions?

example:

$which_day = foo("2002", "3", "Sunday");

would return the date stamp for the 3rd Week' of 2002's Sunday.

In the case of the example should return: "01/13/2002"

Thoughts???

    try something like

    <?
    $week = 5;
    $year = 2002;
    $day = "Tuesday";

    $week--;

    $temp = strtotime("01 January $year + $week weeks $day");
    echo date("m-d-Y", $temp) . "<br>";
    ?>

    HTH

    Toby

      4 years later

      This is a rather old thread but i'm have the same requirement as the original poster and was hoping maybe someone could shed some light on this.

      When I excute this code the date is comes as Nov, 6 when it should really be Oct, 30.

      
      function MkTime($yr, $mth, $day) {
          $Wk = date("w", mktime(1, 1, 1, $mth, 1, $yr));
         /* week equals 44 */
          $MyDay = date("M, j",  strtotime("01 January $yr +$Wk weeks $day"));
                return $MyDay;
        }
      
      echo MkTime(2006, 11, "Monday");
      

      Any help in figuring this out would be great.

        1. [man]mktime/man is already a function -- use a different name.

        2. I believe you want 'W' not 'w' in your date format.

        3. Nov, 6 is the correct date...

          A very similar question was posted just yesterday (in this thread) to which two solutions were offered. Either one of them can be simply modified to solve your problem.

            should infact be week 1

            No infact it's in the 52nd week (of the previous year), as your own code shows:

            /* produces week 52 */ 
            echo date("W", strtotime("1/1/2006"));

            And since, as you yourself say, 10-30 of the same year is in the 44th week, that must be so (check your calendar) unless there are two week ones.

              Write a Reply...