B
B
bismoney2021-06-12 10:27:51
Yii
bismoney, 2021-06-12 10:27:51

Date problem?

Guys please help.

There is

// Это дата добавления пользователя (2021-06-10 08:10:52)
$data1 = new DateTime($client_test->add_time);
// Это дата добавления пользователя (2021-06-11 08:10:52) + 1 day
$data2 = new DateTime($client_test->add_time . ' +1 day');


How to do this:
<? if (data1 > data2) { ?>
  <?php echo "on" ?>
<? } elseif (data1 < data2)) { ?>
<?php echo "off" ?>
<? } ?>


The very essence:
2021-06-10 08:10:52
2021-06-11 08:10:52

That is, 2021-06-11 08:10:52 has already passed, and if it has passed, then we close access.
And if the date + 1 day has not yet passed relative to 2021-06-10 08:10:52, then access is working.

In both cases, access is allowed for me ... I’ve been getting it for 3 hours already ... I don’t understand what’s wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2021-06-12
@bismoney

new DateTime($client_test->add_time . ' +1 day'); is a class. Those. You are comparing class with class. And you need to compare dates or their timestamp.
Perhaps you should equate and use other variables for comparison - ->format('Ymd H:i');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question