- 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
PHP program to change the date format
To change date format in PHP, the code is as follows −
Example
<?php function string_convert ($my_date){ $sec = strtotime($my_date); $my_date = date("Y-m-d H:i", $sec); $my_date = $my_date . ":00"; echo $my_date; } $my_date = "23/11/2020 11:59 PM"; string_convert($my_date); ?>
Output
1970-01-01 00:00:00
A function named ‘string_convert’ is used in PHP that takes a date as a parameter. The ‘strtotime’ function is used to convert English text timing into a UNIX timestamp −
$sec = strtotime($my_date); $my_date = date("Y-m-d H:i", $sec); $my_date = $my_date . ":00";
This date is printed on the screen. Outside the function, the date time is defined, and the function is called on this parameter and the output is displayed on the screen −
echo $my_date;
Advertisements