- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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;
- Related Articles
- PHP program to change date format
- Is there a way to change the date format in php?
- Change date format in MongoDB
- Change date format (in DB or output) to dd/mm/yyyy in PHP MySQL?
- How to change date time format in HTML5?
- Change the curdate() (current date) format in MySQL
- Best way to change the date format in MySQL SELECT?
- How to change date format with DATE_FORMAT() in MySQL?
- How to change date and time format in Android sqlite?
- Java Program to format date with SimpleDateFormat
- Java Program to format date with DateFormat.FULL
- Java Program to format date with System.out.format
- Java Program to format date in mm-dd-yyyy hh:mm:ss format
- Change date format in MySQL database table to d/m/y
- Java Program to format date time with Join

Advertisements