- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL format time with lowercase am/pm?
To format MySQL time with lowercase am/pm, use the LOWER() as well as DATE_FORMAT().Let us first create a table −
mysql> create table formatTime -> ( -> LoginTime time -> ); Query OK, 0 rows affected (0.56 sec)
Following is the query to insert records in the table using insert command −
mysql> insert into formatTime values('12:40:34'); Query OK, 1 row affected (0.20 sec) mysql> insert into formatTime values('14:10:58'); Query OK, 1 row affected (0.13 sec) mysql> insert into formatTime values('16:56:40'); Query OK, 1 row affected (0.18 sec) mysql> insert into formatTime values('10:12:14'); Query OK, 1 row affected (0.16 sec)
Following is the query to display all records from the table using select statement −
mysql> select * from formatTime;
This will produce the following output −
+-----------+ | LoginTime | +-----------+ | 12:40:34 | | 14:10:58 | | 16:56:40 | | 10:12:14 | +-----------+ 4 rows in set (0.00 sec)
Following is the query to format MySQL time with lowercase am/pm −
mysql> select LOWER(DATE_FORMAT(LoginTime,'%l:%i %p')) from formatTime;
This will produce the following output −
+------------------------------------------+ | LOWER(DATE_FORMAT(LoginTime,'%l:%i %p')) | +------------------------------------------+ | 12:40 pm | | 2:10 pm | | 4:56 pm | | 10:12 am | +------------------------------------------+ 4 rows in set (0.04 sec)
Advertisements