CodeIgniter Forums
Database Timestamp ? - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: Database Timestamp ? (/thread-73486.html)

Database Timestamp ? - MeltedRolo - 04-29-2019

Hi guys

Quick question regarding database automatic timestamps.

From the User Guide ...


This boolean value determines whether the current date is automatically added to all inserts and updates. If true, will set the current time in the format specified by $dateFormat. This requires that the table have columns named ‘created_at’ and ‘updated_at’ in the appropriate data type.


This value works with $useTimestamps to ensure that the correct type of date value gets inserted into the database. By default, this creates DATETIME values, but valid options are: datetime, date, or int (a PHP timestamp).

Which do you use and why?

Does the datetime option use the MySql timestamp, or is this not used at all.


RE: Database Timestamp ? - php_rocs - 04-29-2019


When it comes to timestamps you can either use it from the web server where PHP is installed or the database server (assuming that they are not installed on the same server). In most of my cases I've used a combination of both. It just depends on the system and sometimes the location of the web server and or database server.

RE: Database Timestamp ? - MeltedRolo - 04-29-2019


Thanks for the reply.

I would really rather use the time from PHP, and was wondering which of the options above would be ruled out based on that decision, as I have no idea how the database model inserts or doesnt insert the timestamp fields.


RE: Database Timestamp ? - MeltedRolo - 04-29-2019

Hi again.

Is my thinking correct on this.

The default is datetime, so my database columns will need to be VARCHAR(25).

If I choose INT, then my database columns will need to be INT(14).

If i,m using Mysql timestamps, then that's handled by the database, so I should not be using $useTimestamps = true.


RE: Database Timestamp ? - InsiteFX - 04-29-2019

No you use either TIMESTAMP or DATETIME for storing the date / time fields.