- 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
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)
Advertisements
To Continue Learning Please Login
Login with Google