Malasuerte94
Malasuerte94

Reputation: 1474

Check if date from db passed two weeks from the current date

So I have two dates:

$data_db = 2014-08-24;
$curent_date = date(Y-m-d);

and code must be like that

<?php if ($data_db > $curent_date with 14 days){

    echo "expired";

    }
    else
    {
    echo "active";
    }
?>

if current date is bigger then two weeks, it will appear as EXPIRED

Upvotes: 0

Views: 1937

Answers (3)

Skarpi Steinthorsson
Skarpi Steinthorsson

Reputation: 521

If I understand this correctly then you need to check if $data_db is more then two weeks old. This can be accomplished by converting the dates to UNIX Time and see if the $data_db is lower then current date minus two weeks.

<?php if (strtotime($data_db) < strtotime('-14 days')) {

    echo "expired";

    }
    else
    {
    echo "active";
    }
?>

If you need to compare it with $current_date then you can do it like this:

<?php if (strtotime($data_db) < strtotime($current_date) - 86400*14) {

    echo "expired";

    }
    else
    {
    echo "active";
    }
?>

Upvotes: 0

Malasuerte94
Malasuerte94

Reputation: 1474

I have solved myself the problem !

        $expire_date = strtotime($time_db . ' + 14 days');

        if (time() > $expire_date){

            $time_to_pay =  "Expired on ".date('Y-m-d', $expire_date);
        }
        else
        {
            $time_to_pay =  "Active but expire on ".date('Y-m-d', $expire_date);
        }

Upvotes: 1

John Conde
John Conde

Reputation: 219874

There's a lot of ways to do this. Here's a simple one:

<?php if (strtotime($data_db) > strtotime('+14 days')){

    echo "expired";

    }
    else
    {
    echo "active";
    }
?>

Upvotes: 0

Related Questions