Ruslan
August 21, 2018, 12:02pm
1
Hello,
If I have in MySQL table field timestamp type, how to save data?
I get string like ‘1378283588’ (it’s timestamp) and I would like to store it like timestamp in DB.
If I dod $this->save($data['Model"][‘my_time’] = ‘1378283588’ - I get “0000-00-00 00:00:00” . I see it in phpMyAdmin.
hakim
August 24, 2018, 1:40pm
2
I think in MySQL the column type needs to be INT(11) if you want unix style timestamp.
Ruslan
August 25, 2018, 5:59am
3
hakim> Yes, but it INT. MySQL has timestamp type.
hakim
August 28, 2018, 6:35am
4
Dude, MySQL timstamp is not unix time, it’s the data type is used for values that contain both date and time parts. TIMESTAMP has a range of ‘1970-01-01 00:00:01’ UTC to ‘2038-01-19 03:14:07’ UTC.
If you want to save unix time, then the column needs to be INT.
Ruslan
August 28, 2018, 1:57pm
5
hakim> It’s clear.
But if I would like to save dada in a field with timestamp type, How to prepare it?
in MySQL I can use the function FROM_UNIXTIME .
Thank you.
hakim
August 29, 2018, 9:48am
6
It would have to be string iso date format “YYYY-DD-MM HH:MM:SS” … Do you need this for “created” and “modified” columns? Cake can do this for you with timestamp behaviour:
https://book.cakephp.org/3.0/en/orm/behaviors/timestamp.html
So when a record is created or modified, cake will update these for you.
However the column in MySQL needs to be “datetime” not “timestamp” for this to work.
Ruslan
August 29, 2018, 11:55am
7
I know this feature and use it. I get data from another service.