E
E
EvgMul2015-12-07 15:16:49
PHP
EvgMul, 2015-12-07 15:16:49

How to work with dates?

Hello.
There is a following task: from basis it is necessary to get records for a certain period of time. The date is stored in the database in numerical form (for example: 1449500400). At first glance, I see the following work option: we convert it to a normal date and add the required interval through DateInterval, then we convert it back and look for it.
But maybe there is a shorter way to add for example a week to a number in milliseconds?
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander N++, 2015-12-07
@EvgMul

... WHERE created_at BETWEEN @a1 AND @a2
where @a1 = strtotime(date('2015-01-05 00:00:00'))
@a2 = strtotime('-20 days');

A
Adamos, 2015-12-07
@Adamos

MySQL independently knows how to work with dates and times - in particular, convert it to a timestamp and add intervals.
RTFM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question