How to calculate fixed date in php?

Asked

Viewed 86 times

3

Guys, here’s the deal. I need a button to be released only after 8 o'clock on Sunday. For example, the client sends the file to the website. He can send the file on Sunday or Monday at any time. However it will only be released to download next Sunday at 8. Already saved in the bank the date on which it put. But I can’t calculate the exact date to release. Anyone help?

1 answer

4


You can do it using strtotime, with the parameter 'next sunday', take the example:

to write to the database

// formatei no formato que utilizo no banco, e complementei com o horário fixo
echo date("Y-m-d", strtotime('next sunday')) . ' 08:00:00';

Exit:

2016-08-14 08:00:00 // próximo domingo 08h (considerando que hj é 10/08/2016)

to generate the buttons

To check the status of the button:

I created a function that will check if it is to write the button enabled or disabled:

function checaLiberacao($dt_liberacao) {
    $liberado = strtotime($dt_liberacao);
    $agora = strtotime('now');
    if ($liberado <= $agora) {
        echo '';
    } else {
        echo 'botão desabilitado';
    }
}

USE:

$dt_liberacao = '2016-08-14 08:00:00'; // substituir por método para trazer dados do banco
checaLiberacao($dt_liberacao); 

Returns: disabled button

Another example:

$dt_liberacao = '2016-08-09 08:00:00'; // substituir por método para trazer dados do banco
checaLiberacao($dt_liberacao); 

Returns:

button enabled

I hope I’ve helped!

  • 3

    +1 But it might be useful to insert the comparison as well: enable/disable button. To be more complete

  • 2

    Done, just replace the fixed date with the one you bring from the database and implement the method to generate the buttons.

  • Vlw, you solved my problem!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.