- 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
Working with Time in PHP/ MySQL?
To work with time in PHP/ MySQL, you can use strtotime() function. The PHP code is as follows for the same −
$timeValue='8:55 PM'; $changeTimeFormat = date('H:i:s', strtotime($timeValue)); echo("The change Format in 24 Hours="); echo($changeTimeFormat);
The snapshot of PHP code is as follows −
Here is the output.
Here is the MySQL query to get the original time −
mysql> SELECT CONCAT('The change Format in 12 Hours in MySQL=',DATE_FORMAT('2019-03-12 20:55:00', '%l:%i %p')) AS OriginalTimeFormat;
The following is The output −
+------------------------------------------------+ | OriginalTimeFormat | +------------------------------------------------+ | The change Format in 12 Hours in MySQL=8:55 PM | +------------------------------------------------+ 1 row in set (0.00 sec)
Advertisements
To Continue Learning Please Login
Login with Google