Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Convert timestamp coming from SQL database to String PHP?
To convert timestamp to string, use setTimestamp(). Let’s say the following is our input i.e. timestamp −
$SQLTimestamp = 1600320600000;
We want the following output i.e. Date string −
2020-09-17 05:30:00
At first, get seconds from Timestamp −
$seconds = round($SQLTimestamp/1000, 0);
Example
<!DOCTYPE html>
<html>
<body>
<?php
$SQLTimestamp = 1600320600000;
$seconds = round($SQLTimestamp/1000, 0);
$PHPDateObject = new DateTime();
$PHPDateObject->setTimestamp($seconds);
echo $PHPDateObject->format('Y-m-d H:i:s');
?>
</body>
</html>
Output
2020-09-17 05:30:00
Advertisements
