I would like to know how I can do a select with all the Fridays of the year in mysql for example

1

I'm developing a calendar, and it's going to be used to book meetings. There are sectors, such as the T.I sector, for example, that have a meeting every Friday from 9:30 to 11:30, all year round. I need some way, to insert into my "start date" table (of the meeting), every Friday of the year.

I'm using the fullCalendar.io, mysql, and PHP library. Please, someone gives me a light.

    
asked by anonymous 09.06.2018 / 17:40

1 answer

1

You can build an algorithm that gets every Friday of the year and then insert the dates into the database. Here's an example in PHP that gets the dates:

<?php
# Ano a qual deseja obter todas as sexta-feiras.
$ano = 2018;

# Iniciamos a variável data com o primeiro dia do ano.
$data = new DateTime("$ano-01-01 08:30");

# Pecorremos todo o ano para encontrar todas as sexta-feiras.
while ($data->format('Y') == $ano)
{
    # Se sexta-feira
    if ($data->format('w') == 5) 
    {
        # Data sexta-feira.
        echo $data->format('Y-m-d H:i');

        # Depois que descobrimos a primeira sexta-feira do ano. Basta adicionar 7 dias a data
        # para encontrar a próxima sexta feira.
        $data->add(new DateInterval('P7D'));
    } 
    else 
    {
        # Caso a data inicial não seja uma sexta. Adiciona mais uma dia a data.
        $data->add(new DateInterval('P1D'));
    }
}
    
09.06.2018 / 18:23