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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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