note 37120 added to function.time

From: Date: Tue, 04 Nov 2003 04:02:35 +0000
Subject: note 37120 added to function.time
Groups: php.notes 
Request: Send a blank email to php-notes+get-59843@lists.php.net to get a copy of this message
In reference to the note from mwwaygoo about storing timestamps... I have found that storing a datetime and then doing selects based on the mysql function UNIX_TIMESTAMP(field_name) has problems with regard to using indices. For instance, let's say you have a table with a 'start_datetime' and an 'end_datetime' field that holds a standard datetime value and is a true "datetime" field. You have an index that refers to the start_datetime and end_datetime fields in place. However, when you do a select using something like: SELECT * from table_name where UNIX_TIMESTAMP(start_datetime) > 'some_value' AND UNIX_TIMESTAMP(end_datetime) < 'another value' I have noticed problems using those indices when using the EXPLAIN function. Has anyone else encountered this? In my case, I changed the fields to INT and stored the timestamp itself. (it is misleading in that the 'timestamp' field type in mysql holds a datetime value that updates itself unless you explicitly set it). Now when I use EXPLAIN to see which index it will use, it is using the one I created. ---- Manual Page -- http://www.php.net/manual/en/function.time.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37120 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37120&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37120&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#59843) next »