
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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
- Related Articles
- MySQL format time with lowercase am/pm?
- Java Program to Format time in AM-PM format
- Display hour in KK (00-11) format in Java
- Format MySQL CURRENT_TIMESTAMP to AM & PM?
- Java Program to display hour in K (0-11 in AM/PM) format
- Convert MySQL Unix-Timestamp format to date format?
- Format hour in HH (00-23) format in Java
- MySQL query to order timestamp in descending order but place the timestamp 0000-00-00 00:00:00 first?
- How to sort time in AM/ PM in MySQL?
- MySQL query to select date from 00:00 to today’s date
- In which format Year(2) or Year(4) MySQL will return the value of year from date ‘0000-00-00’?
- Convert VARCHAR data to MySQL date format?
- How to convert time seconds to h:m:s format in Python?
- Create MySQL datetime column with default 0000-00-00?
- MySQL query to convert height format to centimeters?

Advertisements