Hobbyist_PHPer Posted May 20, 2012 Share Posted May 20, 2012 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... Quote Link to comment https://forums.phpfreaks.com/topic/262827-help-with-strtotime/ Share on other sites More sharing options...
.josh Posted May 20, 2012 Share Posted May 20, 2012 What timezone is your server located in? What is the server time zone the server goes by? Quote Link to comment https://forums.phpfreaks.com/topic/262827-help-with-strtotime/#findComment-1347094 Share on other sites More sharing options...
Hobbyist_PHPer Posted May 20, 2012 Author Share Posted May 20, 2012 What timezone is your server located in? What is the server time zone the server goes by? My server is set to Central time. Quote Link to comment https://forums.phpfreaks.com/topic/262827-help-with-strtotime/#findComment-1347096 Share on other sites More sharing options...
silkfire Posted May 21, 2012 Share Posted May 21, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/262827-help-with-strtotime/#findComment-1347230 Share on other sites More sharing options...
Jessica Posted May 21, 2012 Share Posted May 21, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/262827-help-with-strtotime/#findComment-1347291 Share on other sites More sharing options...
Hobbyist_PHPer Posted May 21, 2012 Author Share Posted May 21, 2012 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... Quote Link to comment https://forums.phpfreaks.com/topic/262827-help-with-strtotime/#findComment-1347292 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.