Jump to content

Help with strtotime


Hobbyist_PHPer

Recommended Posts

Hi, I have a bit of an issue with my application, I didn't notice until today, Sunday... Apparently PHP sees Sunday as the first day of the week, which I cannot fathom where it got hat notion from... but anyway, so I have the following samples of my code:

    $mondayoflastweek = date('Y-m-d H:i:s', strtotime('monday last week'));
    $sundayoflastweek = date('Y-m-d 23:59:59', strtotime('sunday last week'));

 

The crazy and very troublesome thing about the results of that code is that if you run that today, Sunday, it shows today as last week... So therefore, the next bit of code is just as problematic:

    $mondayofthisweek = date('Y-m-d H:i:s', strtotime('monday this week'));
    $sundayofthisweek = date('Y-m-d 23:59:59', strtotime('sunday this week'));

 

As you can imagine, for payroll, this is causing a big problem... My week starts at precisely 12:00 am on Monday and ends at precisely 11:59 pm on Sunday...

 

Could someone please help me out with this...

Link to comment
https://forums.phpfreaks.com/topic/262827-help-with-strtotime/
Share on other sites

This has nothing to do with what the first day of the week is...

 

I just ran your code and got this:

 

string '2012-05-14 00:00:00' (length=19)            // Last Monday

string '2012-05-20 23:59:59' (length=19)            // Last Sunday

 

What results do you get today, Monday, 21 May?

Link to comment
https://forums.phpfreaks.com/topic/262827-help-with-strtotime/#findComment-1347230
Share on other sites

If you had run it on a Sunday, I think he's saying the wrong sunday comes up.

 

You could probably determine what day of the week it is using date('l') (in which 0=sunday), then determine from that how many seconds to subtract from the current time to get the last week Sunday/Monday or whatever day. Not saying this is better, just what I would try next if the "last week" isn't working.

 

 

Link to comment
https://forums.phpfreaks.com/topic/262827-help-with-strtotime/#findComment-1347291
Share on other sites

If you had run it on a Sunday, I think he's saying the wrong sunday comes up.

 

You could probably determine what day of the week it is using date('l') (in which 0=sunday), then determine from that how many seconds to subtract from the current time to get the last week Sunday/Monday or whatever day. Not saying this is better, just what I would try next if the "last week" isn't working.

 

Thank you, that may be just what I have to do...

Link to comment
https://forums.phpfreaks.com/topic/262827-help-with-strtotime/#findComment-1347292
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.