1

I would like to save timestamp value into column.

If i trying to do by this way:

$SessionData['valid_till'] = time() + WEEK;

I get right number value. But into column is already saved value like this:

0000-00-00 00:00:00

How can i do it right way in CakePHP?

Thanks for any advice.

redrom
  • 11,502
  • 31
  • 157
  • 264
  • Make sure you use date() or DateTime object and the type of your db field is "datetime". – mark Jul 10 '14 at 17:59

1 Answers1

4
 $SessionData['valid_till'] = date('Y-m-d H:i:s', strtotime("+1 week"));
Kai
  • 3,803
  • 1
  • 16
  • 33
  • Is not better to use datetime in this case? I thought that i can save integer values, not formatted date. – redrom Jul 10 '14 at 17:54
  • At least with MySQL, though the datatype timestamp seems to be implemented behind the scenes as a unix timestamp, you deal with the data as a formatted string, the same as datetime. http://dev.mysql.com/doc/refman/5.5/en/datetime.html As for when timestamp should be used, people generally say for "created" and "updated" only -- See http://stackoverflow.com/questions/409286/datetime-vs-timestamp – Kai Jul 10 '14 at 18:01