I have a page where I get a date/time to insert into a MySQL database.
The timezone the server in is two hours ahead.
In my php.ini I have date.timezone = America/Los_Angeles
I noticed sometimes the time was off by two hours.
MySQL field is type datetime, not null (and I just notice I haven’t set default value)
I’m using Codeigniter, if that matters.
This is how I get the time to insert into the database:
$newData['time'] = $time = date("Y-m-d G:i:s");
I inserted a line of code after that to write the time to the error log.
log_message('error', "Date time is $time");
Why is the time changing like this? This portion of the log is from 2:00pm to 2:30pm local time.
This is all coming from a single page on my site in the span of 29 minutes.
110 ERROR - 2011-12-20 14:00:57 --> Date time is 2011-12-20 14:00:57
111 ERROR - 2011-12-20 14:01:38 --> Date time is 2011-12-20 14:01:38
112 ERROR - 2011-12-20 14:01:57 --> Date time is 2011-12-20 14:01:57
113 ERROR - 2011-12-20 16:02:19 --> Date time is 2011-12-20 16:02:19
114 ERROR - 2011-12-20 16:02:28 --> Date time is 2011-12-20 16:02:28
115 ERROR - 2011-12-20 14:03:26 --> Date time is 2011-12-20 14:03:26
116 ERROR - 2011-12-20 14:03:32 --> Date time is 2011-12-20 14:03:32
117 ERROR - 2011-12-20 14:03:46 --> Date time is 2011-12-20 14:03:46
118 ERROR - 2011-12-20 14:04:43 --> Date time is 2011-12-20 14:04:43
119 ERROR - 2011-12-20 14:04:53 --> Date time is 2011-12-20 14:04:53
120 ERROR - 2011-12-20 14:04:58 --> Date time is 2011-12-20 14:04:58
121 ERROR - 2011-12-20 14:05:03 --> Date time is 2011-12-20 14:05:03
122 ERROR - 2011-12-20 16:07:05 --> Date time is 2011-12-20 16:07:05
123 ERROR - 2011-12-20 16:07:25 --> Date time is 2011-12-20 16:07:25
124 ERROR - 2011-12-20 16:07:54 --> Date time is 2011-12-20 16:07:54
125 ERROR - 2011-12-20 16:08:05 --> Date time is 2011-12-20 16:08:05
126 ERROR - 2011-12-20 16:08:15 --> Date time is 2011-12-20 16:08:15
127 ERROR - 2011-12-20 16:09:04 --> Date time is 2011-12-20 16:09:04
128 ERROR - 2011-12-20 16:09:14 --> Date time is 2011-12-20 16:09:14
129 ERROR - 2011-12-20 16:09:44 --> Date time is 2011-12-20 16:09:44
130 ERROR - 2011-12-20 16:10:08 --> Date time is 2011-12-20 16:10:08
131 ERROR - 2011-12-20 16:10:27 --> Date time is 2011-12-20 16:10:27
132 ERROR - 2011-12-20 14:12:16 --> Date time is 2011-12-20 14:12:16
133 ERROR - 2011-12-20 14:15:30 --> Date time is 2011-12-20 14:15:30
134 ERROR - 2011-12-20 14:16:20 --> Date time is 2011-12-20 14:16:20
135 ERROR - 2011-12-20 14:17:55 --> Date time is 2011-12-20 14:17:55
136 ERROR - 2011-12-20 14:18:51 --> Date time is 2011-12-20 14:18:51
137 ERROR - 2011-12-20 14:19:16 --> Date time is 2011-12-20 14:19:16
138 ERROR - 2011-12-20 14:20:08 --> Date time is 2011-12-20 14:20:08
139 ERROR - 2011-12-20 14:27:29 --> Date time is 2011-12-20 14:27:29
140 ERROR - 2011-12-20 14:29:31 --> Date time is 2011-12-20 14:29:31
141 ERROR - 2011-12-20 14:29:55 --> Date time is 2011-12-20 14:29:55
Can anyone shed some light on this for me?
Thanks,
Mark
My guess would be an issue with your system time itself like meouw said, or as John B mentioned, the PHP timezone might be getting overwritten somewhere in your CI config.
Assuming you’re running a linux/gnu box, you should change your error logging to something like this:
log_message('error', "PHP time is $time, System time is ".exec('date'));Which should at least let you know if the issue is with your system time or PHP’s time
(Note: You’re looking for the system time jumping hours apart like your PHP time does, system time being a second or two different from your PHP time is normal)