B
B
banny_name2015-10-15 16:55:43
PHP
banny_name, 2015-10-15 16:55:43

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

2 answer(s)
I
Ivan Ignatiev, 2015-10-15
@banny_name

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.

M
MaEcTPo, 2015-10-15
@MaEcTPo

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'); // упрощённый формат.

For more information, see the link to the documentation for the format()
method. PS It's not entirely clear from the wording of your question what exactly you want to get answered. Re-read questions before submitting, use commas, and formulate the question clearly and concisely.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question