
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
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
- Related Articles
- How to convert from Unix timestamp to MySQL timestamp value?
- Convert date string to timestamp in Python
- Get unix timestamp from string without setting default timezone in PHP
- Convert string (varchar) to timestamp format in MySQL?
- Strategies For Migrating From SQL to NoSQL Database?
- PHP program to convert a given timestamp into time ago
- Convert MySQL timestamp to UNIX Timestamp?
- How to convert timestamp string to datetime object in Python?
- Convert dd/mm/yyyy string to Unix timestamp in MySQL?
- How to convert unix timestamp string to readable date in Python?
- Run SQL file in MySQL database from terminal?
- How to convert array to string PHP?
- Set Database From Single User Mode to Multi User in SQL?
- How to convert string to boolean in PHP?
- SQL Query to Convert Rows to Columns in SQL Server

Advertisements