Answer the question
In order to leave comments, you need to log in
How to write down and work with the date in the future?
It is necessary to write down the time of action in the database.
How to make the year completely written? $date = date('Y.m.d H:i:s');// 13.11.22 03:10:25
I learn, I write down, the line turns out:
"11/13/22 03:10:25"
How to work with it in the future.
for example, you need to output a line: Действие совершено: 13 11 2022 в 03:10
I use seconds to compare dates, they are not needed here ...
Answer the question
In order to leave comments, you need to log in
The standard approach is to store a timestamp (the number of seconds elapsed since 01/01/1970) and convert it to the correct format before outputting it.
If the type in the database is `datetime`, then I would suggest operating on the date as a \DateTime() object.
To create an object, you can use the createFromFormat()
method.
To write it later, use standard constants:
$dateTime = new DateTime() // создаст объект со текущим временем
echo $dateTime->format(\DateTime::ATOM) // покажет дату в формате, необходимом для базы данных.
echo $dateTime->format('Y-m-d H:i:s'); // упрощённый формат.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question