Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert PHP variable “11:00 AM” to MySQL time format?
Use DateTime to convert PHP variable “11:00 AM: to MySQL time format.
The PHP code is as follows −
$phpTime = '11:00 AM';
echo('The PHP Time Format is =');
echo ($phpTime);
$timeFormat = DateTime::createFromFormat( 'H:i A', $phpTime);
$MySQLTimeFormat = $timeFormat->format( 'H:i:s');
echo ('
');
echo('The MySQL Time Format is =');
echo ($MySQLTimeFormat);
The snapshot of PHP code is as follows −

Here is the output −
The PHP Time Format is =11:00 AM The MySQL Time Format is =11:00:00
Advertisements