U
U
Us592019-04-17 18:11:02
PHP
Us59, 2019-04-17 18:11:02

How to compare date and time?

The date and time are stored in the database in this format:
2019-04-17 07:59:27

The script runs once a minute, you need to compare the time and date (just in case) if 1 hour and 30 minutes have passed, I will do some action, otherwise break;

date('Y-m-d h:i:s') // вот так записывается дата и время в БД.


I looked at Google, but there are examples where they compare time in seconds, as far as I understand, I have a different case.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evgeny Samsonov, 2019-04-17
@bitniks

$date = new \DateTime('2019-04-17 07:59:27');
if ($date < (new \DateTime('-1 hour -30 minutes'))) {
    // действие, если прошло больше 1 часа 30 минут
}

O
Oleg Gamega, 2017-02-28
@gadfi

As I understand it, the best option is to choose some BaaS,

I strongly disagree, but in some cases the same firebase saves, but a full-fledged server is much more convenient and stable
. I am not against third-party services when they are really needed, but no more.
the same firebase is good for realtime, but there are a number of standard tasks that fit better on real databases and make them a pain on various BaaS

P
Puma Thailand, 2017-02-28
@opium

baas is good for some small applications, all applications from medium ones clearly require their own backend.
for the backend there is a solution from the same google,
but it’s easier in google and search
https://www.google.ru/webhp?sourceid=chrome-instan...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question