Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts

    strtotime monday of the previous week

    Hi,

    I'm trying to get the date of the Monday from the previous week.
    I've tried strtotime(-1 week last Monday) and monday - 1 week without any luck. It seems to look at todays day of the week one week ago, ignoring the 'last Monday' part.
    Its a little confusing as the term 'last' refers to the current week.

    Its worth pointing out that this is for yahoo pipes' date builder.

    Any ideas?
    Thanks
    Last edited by htcilt; 09-11-2009 at 03:20 PM.

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    try this:

    PHP Code:
    $StartOfLastWeek date("w",mktime());
    echo 
    date('Y-m-d'strtotime("-$StartOfLastWeek day") ); 
    Last edited by angst; 09-11-2009 at 04:03 PM.

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks for the quick reply.
    Unfortunately I'm a bit limited by Yahoo Pipes. The contents of its date builder are basically php's strtotime function, but you can only type in what goes inbetween the function brackets.

    Have a quick look Here:
    http://pipes.yahoo.com/pipes/docs?do...vm=r#DateInput

    Cheers

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by angst View Post
    try this:

    PHP Code:
    $StartOfLastWeek date("w",mktime());
    echo 
    date('Y-m-d'strtotime("-$StartOfLastWeek day") ); 


    That solution gives me Sunday, August 30th. In this case, the correct date should be Monday, September 7th.

    Give this a shot. If the current day is Sunday or Monday, it will give you the date a week prior.
    PHP Code:
    echo date'Y-m-d'strtotime'last monday' ) ); 
    Last edited by kbluhm; 09-11-2009 at 04:03 PM. Reason: To comply w/ Yahoo Pipes

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ah ok, I didn't really test it, but the only change would be to change the 7 to a 6 to account for day 0. however either way this doesn't solve his issue with yahoo pipes ( which I've never heard of ).

  • #6
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    I've edited my solution to comply w/ Yahoo Pipes.

    And your solution would take a bit more than just accounting for `0`, since today is Friday, which is `5`.

  • #7
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    By a week last Monday, I would expect the 31st August.
    I was hoping this would be achievable within the brackets, like "last Monday - 1 week", but things are never that simple lol!

    I've posted a message on the Yahoo pipes forum. Hopefully someone will have a solution.

    Thanks everyone.

  • #8
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by htcilt View Post
    By a week last Monday, I would expect the 31st August.
    I was hoping this would be achievable within the brackets, like "last Monday - 1 week", but things are never that simple lol!

    I've posted a message on the Yahoo pipes forum. Hopefully someone will have a solution.

    Thanks everyone.
    Oh oh oh oh ohhh... The Monday of the prior week. I understood it as the prior Monday. Oops.

  • #9
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    hehe, thats okay, it is confusing
    But yeah, the complexity comes from it being last week, not the current week.

    Its strange because -1 week works, but not in combination with last Monday

  • #10
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    Quote Originally Posted by kbluhm View Post

    And your solution would take a bit more than just accounting for `0`, since today is Friday, which is `5`.

    what are you talking about? i updated and tested my function and it works correctly.

  • #11
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by angst View Post
    what are you talking about? i updated and tested my function and it works correctly.
    As I originally stated, your code returned 2009-08-30, which is a Sunday.

    Sunday != Monday

    Regardless, this cannot be achieved with a cleverly formatted string. You will need some logic involved, which I guess Pipes does not allow.


  •  

    Posting Permissions

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