Problems with daylight saving time (when returning timestamp) database

Asked

Viewed 154 times

0

I’m having a headache after October 19, as was usual the summer time, and this year there were no, some clients performing some tasks in my school attendance system, while saving a date that is saved in the standard timtestamp, some dates were saved with 1 hour less, example using epochconverter:

Timestamp in bd is = 1573610400 GMT: Wednesday, 13 November 2019 02:00:00 Your time zone: Wednesday, November 13, 2019 at 00:00:00 GMT-02:00 DST

While the timestamp should be = 1573614000 GMT: Wednesday, 13 November 2019 03:00:00 Your time zone: Wednesday, November 13, 2019 at 01:00:00 GMT-02:00 DST

This error only happened in a few days of the months of October and November after the 19th and October. That is why the system does not return the student’s frequency on the day.

My question is, "Is it possible to create a php function that searches for the timestamp of the day by ignoring the time or Timezone? My code used:

$attendance = $this->db->get_where('attendance', array(
  'section_id' => $section_id,
  'class_id' => $class_id,
  'year' => $running_year,
  'timestamp' => $timestamp,
  'student_id' => $row->student_id
  ))->result_array();


 foreach ($attendance as $row1) :
  $month_dummy = gmdate('d', $row1['timestamp']);

  if ($i == $month_dummy) {
   $status = $row1['status'];
  }
  • 1

    Timestamp has no time zone, if recorded a time zone considering then recorded wrong, I think the best solution is to fix the data in DB. Timestamp should always be UTC.

  • @Maniero also did not understand why this happened, I’m already converting in the comic, grateful.

  • It happened because you recorded wrong.

  • Exactly as they said, ended up recording wrong data in db, you will be able to update correctly the affected column with an UPDATE, but before that, I suggest you change in php configuration file (php.ini) or in the code itself Timezone, I am using America/Fortaleza for not being affected by daylight saving time

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.