Jump to content

stratotime inbetween dates


hyster
Go to solution Solved by Barand,

Recommended Posts

I'm trying to get an if statement to determine inbetween 2 dates.

I can get it working if its older than -7 days (single argument) but when I try to add the 2nd condition I get syntax error

$timestamp is coming from a json - unix timestamp

$timestamp = $output2['data'][$acc_id]['last_battle_time'];


$my_date = date('Y-m-d',$timestamp);


if( strtotime($my_date) > strtotime('-7 day') && < strtotime('-14 day') ) {
    echo '   7';
}
Link to comment
Share on other sites

I made a basic error :$

 

now I'm stuck with the following, noting happens but the code "executes"

I'm trying to get when the person was last online in a weekly group, 7 - 14 - 21 -28 - over days days ago

$timestamp = $output2['data'][$acc_id]['last_battle_time'];


$my_date = date('Y-m-d',$timestamp);


if( strtotime($my_date) >= strtotime('-1 day') && strtotime($my_date) <= strtotime('-7 day') ) {
    echo '   7';
}elseif( strtotime($my_date) >= strtotime('-7 day') && strtotime($my_date) <= strtotime('-14 day') ) {
    echo '   14';
}elseif( strtotime($my_date) >= strtotime('-14 day') && strtotime($my_date) <= strtotime('-21 day') ) {
    echo '   21';
}elseif( strtotime($my_date) >= strtotime('-21 day') && strtotime($my_date) <= strtotime('-28 day') ) {
    echo '   28';
}
Link to comment
Share on other sites

Aside from Barand's response, I would add the following comments on your code.

 

In the first code you posted, the conditions in the if() clause was wrong. Each condition joined with AND/OR clauses must be independent.

 

if( strtotime($my_date) > strtotime('-7 day') && < strtotime('-14 day') ) {

The red condition is incomplete.

 

 

On your second posted code, the conditions are impossible!

 

 

 

if( strtotime($my_date) >= strtotime('-1 day') && strtotime($my_date) <= strtotime('-7 day') ) {

echo ' 7';
}

A date cannot be greater than yesterday (-1) AND also be less than 7 days ago. The operators need to be reversed.

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.