2

Sorry if this seems like a stupid question. I'm probably missing something obvious but I've been struggling with this for ages and am getting nowhere. I've tried searching but haven't been able to find anything specific enough so I'm asking here in the hope that someone smarter than me can help me out.

I'm using the following line of PHP code to get the timestamp of the beggining of the current week.

strtotime(date('o-\\WW', time()));

This works fine on my local server and it worked fine on my live shared hosting, but now that I have moved my site to a virtual dedicated server it returns a blank.

The date() part is working fine on all servers ie.

date('o-\\WW', time()) today returns 2012-W11 on all servers

Therefore the problem is with the way strtotime turns 2012-W11 into a timestamp ie a problem with running strtotime('2012-W11')

I'm guessing there must be a difference in the way the new virtual dedicated server is set up that is causing it not to be able to do this in the expected way but I can't for the life of me work out what it is.

Thanks in advance for your help

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
365SplendidSuns
  • 3,175
  • 1
  • 21
  • 28
  • 1
    What OSs are the servers running? – Pekka Mar 18 '12 at 16:07
  • CentOS I believe on the new virtual dedicated server. The local server was on windows and the shared hosting was Linux but I don't know anything more specific than that. – 365SplendidSuns Mar 18 '12 at 16:09
  • 1
    I'm not sure what can be done to fix this - if anything *can* be done. Here's an alternative way of doing your desired calculation. http://stackoverflow.com/questions/1897727/get-first-day-of-week-in-php – Pekka Mar 18 '12 at 16:12
  • Thanks. If I can't fix it I'll probably have to look at one of these ways of doing it instead. For the momnet I'll try to fix it. Thanks for your help. – 365SplendidSuns Mar 18 '12 at 16:16
  • An idea only: What about locales? Do they differ / have changed? – hakre Mar 18 '12 at 16:21
  • Nah, Ive set the default time zone to UTC in all cases. I dont think locale is the problem – 365SplendidSuns Mar 18 '12 at 16:34

2 Answers2

1

try changing the format to strtotime('2012 +11 weeks')

Chris Fazzio
  • 375
  • 1
  • 6
  • 16
  • Tested that and it does return a timestamp! It's not quite the right one though as I guess it is returning + 11 weeks from the start of 2012 regardless of the day of the week 2012 started rather the timestamp of the beggining of the 11th week. Certainly a good point to work from though so thanks. – 365SplendidSuns Mar 18 '12 at 16:33
0

you can use below code get first day of the current week

$weekFirstDay = strtotime('Monday this week');

it's from PHP Manaul

young
  • 1
  • 1
  • This does the trick but it's a week ahead. Being Sunday today that may have something to do with the definition of when the week starts in each case. I'll have a play around but this will surely do it. – 365SplendidSuns Mar 18 '12 at 16:42