SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    date "W" offset option

    I have a timesheet system which is like a calendar and used to work but now the client needs the starting date to be on a tuesday instead of a monday.

    The basic code is as follows:

    PHP Code:
    // ORIGINAL YYYY-MM-DD
    $datex explode("-",$timesheet["Timesheet"]['date']);

    $oldts mktime(0,0,0,$datex[1],$datex[2],$datex[0]);

    $week=date("W",$oldts); 
    How would I go about changing this so it thinks the tuesday is the start of the week and monday is the last day of the week.

    Thankyou

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    If date($oldts,'w') == 1, $week--;

    Sometimes it's not a question of making the function do what you want, but working with what it gives you

    PS: You could also have gotten $oldts by doing a strtotime on the original date - strtotime takes Y-m-d as valid input.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, it didn't seem to change anything. I changed it as follows though:
    PHP Code:
     if (date("W"$oldts) == 1) { $week--; } 
    I thought it might have to do with the timestamp, changing that back one day or similar.

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    You got the wrong w. look closer. (w = day of week. W = week of year)
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thankyou, that changed some of the weeks around. Do you mind telling me which $week-- is doing or where I can look into it further to understand?

    Thanks

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    -- is "decrease by one"
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thankyou for your help!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •