How to calculate fixed date in php?

3

Well, guys, this is it. I need a button to be released only after 8 o'clock on Sunday. For example, the client sends the file to the site. It can send the file on Sunday or Monday at any time. But he will only be released to download the next Sunday the 8th. Saved in the bank the date in which he posts. But I can not calculate the exact date to release. Anyone help?

    
asked by anonymous 10.08.2016 / 22:04

1 answer

4

You can do this by using strtotime , with the 'next sunday' parameter, see 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';

Output:

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 type the enabled or disabled button:

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

Return:

  

button enabled

I hope I have helped!

    
10.08.2016 / 22:13