I would like to know how can I make a select with every Friday of the year in mysql for example

I am developing a calendar, and it will be used to schedule meetings. There are sectors, such as the I. T. sector for example, that have meeting every Friday, from 9:30 to 11:30, all year round. I need to somehow, enter in my table "start date" (of the meeting), every Friday of the year.

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

Author: Diego Marcelo, 2018-06-09

1 answers

You can build an algorithm that gets every Friday of the year and then enter the dates into the database. Here is 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'));
    }
}
 1
Author: Thiagosilr, 2018-06-09 16:47:19