Save only day and month in mysql DATE field with php?

Asked

Viewed 725 times

1

I need to register commemorative dates in the database, but I only need the day and month, the year is not relevant and does not need to be registered. My question is this, I can only save the day and the month in the field Date do MYSQL? or better save in text field? And then recover with function date do php, 'cause I’m gonna need to do a function to calculate that the date is close when it’s only five days away. Example:

<label>Nome Data:
<input type="text" name="data_comemorativa"/>
</label>
<br><br>
<label>Data:
<input type="text" placeholder="dia / mês" name="data"/>
</label>
<br><br>
<button name="Salvar">Salvar</button>

<!--
Depois em php farei a busca no banco todos os dias e farei um alerta para quando estiver faltando apenas 5 dias para o evento e alertado até o dia do evento
"falta 5 dias para...."
"falta 4 dias para ..."
"até o dia do evento"

para o calculo em php vou pegar o ano atual mais o dia e mes vindo do banco.
-->

Or better save the day and month with the current year?

1 answer

2


Personally I would keep with the current year in format of Date.

The Mysql has date functions to remove only the month or day from a date so it can do all the calculations in the same, and if for some reason you need the whole date it is there to be used.

  • Perfect @Isac, I was wondering if you would do it anyway.

Browser other questions tagged

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