0

PHP Timestamp conversion to date returning a date with 1970 as the year

Am capturing login time to be used in setting the base time to be applied in ending the session if the time exceeds five minutes... i have captured the login time from login page as <?php ..... $_SESSION["start"]=time(); ?> and then i have called that stored variable from the session and used it on my Orders.php page which is returning a false date of 1970... <?php .... $p=$_SESSION["start"]; $c=$p/1000; date_default_timezone_set("Africa/Nairobi"); echo date('D M d Y H:i:s', $c); ?> The date is returning a false time stamp please help

17th Aug 2020, 12:23 PM
Timothy Njiru
Timothy Njiru - avatar
7 Answers
+ 1
you dont need to divide the time with 1000
17th Aug 2020, 12:32 PM
Taste
Taste - avatar
+ 1
because date() need milisecond but the the code you supply it with second.
17th Aug 2020, 12:45 PM
Taste
Taste - avatar
0
Even if the time is in milliseconds which i assume is the default format for timestamps
17th Aug 2020, 12:34 PM
Timothy Njiru
Timothy Njiru - avatar
0
yep. date() function require milisecond.
17th Aug 2020, 12:36 PM
Taste
Taste - avatar
0
Yeah so the code is okay but the compiler is returning 1970
17th Aug 2020, 12:37 PM
Timothy Njiru
Timothy Njiru - avatar
0
So i should supply the date function a timestamp which is in milliseconds?
17th Aug 2020, 12:46 PM
Timothy Njiru
Timothy Njiru - avatar
0
It worked bro your really good at this man
17th Aug 2020, 12:47 PM
Timothy Njiru
Timothy Njiru - avatar