I am setting a Database value within from a PHP file. In php file i have a string variable which stores unix timestamp value.
MySql table i am having is having a schema where i have to store these timestamp values in login field which is of timestamp datatype.
i tried sending
date('Y-m-d G:i:s', strtotime($userLogin));
to my database but all it stores is 0000-00-00 00:00:00
strtotime () is intended for converting strings in various date formats into UNIX timestamps. If the string is a timestamp already then it won’t look like a meaningful formatted date/time to strtotime () and it will fail.
If the string is already a timestamp, then you don’t need to do anything more to it than cast it to integer (strictly speaking even that step shouldn’t be necessary, but casting will strip out any non-numerical characters, so it doesn’t usually hurt to cast)
Additionally, MySQL is capable of parsing UNIX timestamps (with FROM_UNIXTIME(), I think, I’d have to look it up to be sure)