Answer the question
In order to leave comments, you need to log in
How to correctly compare different date formats?
The date is stored in this format:
SQL query:
$period = 0;
$time = time();
switch ($data->filter) {
case 'week': $period = $time - (60 * 60 * 24 * 7); break;
case 'month': $period = $time - (60 * 60 * 24 * 30); break;
default: $period = $time - (60 * 60 * 24); break;
}
$data = (object)[
'user_id' => $data->userId,
'period' => $period,
];
$enrollments = $this->model->getEnrollments($data);
public function getEnrollments($data) {
$params = [
'user_id' => $data->user_id,
'period' => $data->period,
];
return $this->db->row('SELECT id, amount, DATE_FORMAT(date, "%h:%i:%s %d.%m.%Y") as date FROM enrollments WHERE user_id = :user_id && status = 1 && FROM_UNIXTIME(date) > :period ORDER BY id DESC', $params);
}
Answer the question
In order to leave comments, you need to log in
number of seconds since the beginning of 1970
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question