Convert a date format in PHP

How to change date format in PHP?

 

PHP provides strtotime() and date() functions for converting date-time format. We convert the date format from one format to another. For example - we have stored the date in a variable in MM-DD-YYYY format, and we want to convert it to DD-MM-YYYY format.

We can achieve this conversion using strtotime() and date() functions. These are built-in functions of PHP. strtotime() first converts the date to seconds, and then the date() function is used to reconstruct the date in any format. Below are some examples for converting date format.


 


 

 


The date_format() function returns a date formatted according to the specified format.

Note: This function does not use locales (all output is in English).

Tip: Also look at the date() function, which formats a local date/time.

 

 

<?php 

$originalDate = "2010-03-21";

$newDate = date("d-m-Y", strtotime($originalDate));

 ?>

Our Best Popular Projects & Posts

Post Link
School Management System With Full Source Code In php click here
ecommerce project in php click here
simple login and registration form in php click here
Synopsis for online rooms booking project based on PHP click here
add multiple images in codeigniter click here
beginners project in php with source code click here
dynamic country state dropdown in codeigniter click here
how to generate pdf using dompdf in codeigniter click here
add 1 day to current date in php click here
how to check website/blog responsive or not? click here
employee attendance management system project in php with source code click here
Select one checkbox and disable others click here
printing div content with css applied click here
best restaurants management system in php click here
Preview an image before it is uploaded using jquery click here
text editor in jquery click here
data table with export button in html click here
add multiple images in codeigniter click here
codeigniter some steps to install on Your server click here
ajax in php/codeigniter click here
Create Simple API CRUD with PHP and MySQL click here
How to integrate bootstrap theme in codeigniter click here
how to prepare for interview click here
Convert a date format in PHP click here
how to export html table to excel in jquery click here
how to create duplicate google peg using ajax click here
how to make dropdown searchable in html using jquery click here
how to find retirement date in php click here
online food order system in php with source code click here
school management project admin panel in php click here

0 Comments