
- 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
Format MySQL CURRENT_TIMESTAMP to AM & PM?
To format, use DATE_FORMAT(). Let us first create a table
mysql> create table DemoTable ( LoginTime time ); Query OK, 0 rows affected (0.48 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('13:10'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('20:08'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('10:55'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('16:40'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+ | LoginTime | +-----------+ | 13:10:00 | | 20:08:00 | | 10:55:00 | | 16:40:00 | +-----------+ 4 rows in set (0.00 sec)
Following is the query to format CURRENT_TIMESTAMP to AM & PM −
mysql> select date_format(LoginTime,'%r') from DemoTable;
This will produce the following output −
+-----------------------------+ | date_format(LoginTime,'%r') | +-----------------------------+ | 01:10:00 PM | | 08:08:00 PM | | 10:55:00 AM | | 04:40:00 PM | +-----------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL format time with lowercase am/pm?
- Java Program to Format time in AM-PM format
- How to sort time in AM/ PM in MySQL?
- How do you display JavaScript datetime in 12hour AM/PM format?
- Java Program to display hour in K (0-11 in AM/PM) format
- Convert MySQL Unix-Timestamp format to date format?
- AM and PM Full Form (AM Full Form (Anti Meridiem, PM Full Form (Post Meridiem)
- Display hour in h (1-12 in AM/PM) format in Java
- Display hour in hh (01-12 in AM/PM) format in Java
- Set current date and time to timestamp in MySQL
- Convert string (varchar) to timestamp format in MySQL?
- Java Program to display hour and minute in AM or PM
- Convert PHP variable “11:00 AM” to MySQL time format?
- Display Timestamp before the current date in MySQL
- Convert UNIX timestamp into human readable format in MySQL?

Advertisements