Jump to content

if strtorime is not working


williamvdh

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/256155-if-strtorime-is-not-working/
Share on other sites

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..

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'));

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?

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.