williamvdh Posted February 1, 2012 Share Posted February 1, 2012 I have the following code: $current_time = strtotime('now'); if ($current_time > strtotime('monday this week 00:00:01') && $current_time < strtotime('saturday this week 23:59:59')) { $class = "nieuwsinhoudrood"; } else { $class = "nieuwsinhoud"; } I was expecting this to result in $class = "nieuwsinhoudrood", however, this is resulting in $class = "nieuwsinhoud". I do not see where this code is wrong. Hopefully someone can help me. Edit: The servertime is right, I checked this. Quote Link to comment https://forums.phpfreaks.com/topic/256155-if-strtorime-is-not-working/ Share on other sites More sharing options...
Pikachu2000 Posted February 1, 2012 Share Posted February 1, 2012 Echo the values strtotime is returning and see what they are, and how they compare to what you expect them to be. Quote Link to comment https://forums.phpfreaks.com/topic/256155-if-strtorime-is-not-working/#findComment-1313167 Share on other sites More sharing options...
williamvdh Posted February 1, 2012 Author Share Posted February 1, 2012 Echo the values strtotime is returning and see what they are, and how they compare to what you expect them to be. Thanks for your quick reply, I did it: if (1328058862 > 1328482801 && 1328058862 < 1328396399) { This means that Wednesday 01-02-12 02:19:16 (got this from php_date) is not greater than monday this week 00:00:01.. Quote Link to comment https://forums.phpfreaks.com/topic/256155-if-strtorime-is-not-working/#findComment-1313170 Share on other sites More sharing options...
Pikachu2000 Posted February 1, 2012 Share Posted February 1, 2012 Using date, look at the actual dates being returned. You'll see what's happening immediately. echo date('Y-m-d', strtotime('now')) . '<br>'; echo date('Y-m-d', strtotime('monday this week 00:00:01')) . '<br>'; echo date('Y-m-d', strtotime('saturday this week 23:59:59')); Quote Link to comment https://forums.phpfreaks.com/topic/256155-if-strtorime-is-not-working/#findComment-1313200 Share on other sites More sharing options...
williamvdh Posted February 1, 2012 Author Share Posted February 1, 2012 Using date, look at the actual dates being returned. You'll see what's happening immediately. Your script echoed this: 2012-02-01 2012-02-06 2012-02-04 So monday this week = monday next week. When I do this: <?php echo date('Y-m-d', strtotime('now')) . '<br>'; echo date('Y-m-d', strtotime('monday this week 00:00:01')) . '<br>'; echo date('Y-m-d', strtotime('monday last week 00:00:01')) . '<br>'; echo date('Y-m-d', strtotime('saturday this week 23:59:59')); ?> I get this output: 2012-02-01 2012-02-06 2012-01-30 2012-02-04 So monday last week gives me this week's monday. What is happening? Quote Link to comment https://forums.phpfreaks.com/topic/256155-if-strtorime-is-not-working/#findComment-1313365 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.