php

Convert a date YYYY-MM-DD to DD-MM-YYYY in PHP

In this tutorial, we are going to see how to write a PHP script to convert a date from YYYY-MM-DD to DD-MM-YYYY. You can first use the PHP strtotime() function to convert any textual date to the Unix timestamp, then simply use the PHP date() function to convert that timestamp to the desired date format.

The following example will convert a date from the format YYYY-MM-DD to DD-MM-YYYY.
 

Convert a date YYYY-MM-DD to DD-MM-YYYY in PHP
<?php
	$date = "2021-05-25";
	 
	// Create the timestamp from the given date
	$timestamp = strtotime($date);
	 
	// Create the new format from the timestamp
	$date = date("d-m-Y", $timestamp);
	echo $date;
?>

Output:

25-05-2021

 
[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *