...

View Full Version : strtotime monday of the previous week



htcilt
09-11-2009, 02:07 PM
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 :)

angst
09-11-2009, 02:23 PM
try this:



$StartOfLastWeek = 6 + date("w",mktime());
echo date('Y-m-d', strtotime("-$StartOfLastWeek day") );

htcilt
09-11-2009, 02:46 PM
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?doc=user_inputs&vm=r#DateInput

Cheers

kbluhm
09-11-2009, 02:48 PM
try this:



$StartOfLastWeek = 7 + 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.


echo date( 'Y-m-d', strtotime( 'last monday' ) );

angst
09-11-2009, 02:52 PM
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 ).

kbluhm
09-11-2009, 03:01 PM
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`. ;)

htcilt
09-11-2009, 03:02 PM
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.

kbluhm
09-11-2009, 03:06 PM
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.

htcilt
09-11-2009, 03:18 PM
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 :(

angst
09-11-2009, 03:22 PM
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.

kbluhm
09-11-2009, 08:55 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum