- 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
Is there a way to change the date format in php?
Yes, change the date format in PHP using the date() along with strtotime(). Let’s say the following is our date −
$dateValue = "2020-09-19";
Change the date format using the strtotime() method −
$modifiedDate= date("d-m-Y", strtotime($dateValue));
Example
<!DOCTYPE html> <html> <body> <?php $dateValue = "2020-09-19"; echo "The original date format is=",$dateValue,"<br>"; $modifiedDate= date("d-m-Y", strtotime($dateValue)); echo "The changed date format is= ".$modifiedDate; ?> </body> </html>
Output
This will produce the following output
The original date format is=2020-09-19 The changed date format is= 19-09-2020
Advertisements