How to Convert String Date to Date Format in PHP?

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Hello Dev’s
Hope all are feeling okay. Today in this post I will show you how to convert string date to date format. Whenever many of times we  need to convert string date to datetime as like m/d/Y, Y-m-d, d-m-Y etc in php application. We can easily convert from string date to specific date formate in php application. Now We can do by use date() for converting string date to format. We can also do same by set timezone. Before convert a string date to date in php application.

In this post i will give you very shortly and simple way to convert a php string date to a date formation. I will give you best two examples to understand how we will do a php string date format conversion. So also added output of that php application.

Read Also : How to Include Blade File with Data in Laravel?

So, let’s start and see both of examples. You can understand how it works.

Example 1:

<?php
  	
    $myStringDate = "1564079400";
  
    date_default_timezone_set('Asia/Dhaka');
   
    $newDateFormat = date('m/d/Y', $myStringDate);
  
    print_r($newDateFormat);
?>

Output:

07/26/2019
Read Also: How to Install Vue JS in Laravel 8 ?

Example 2:

<?php
  	
    $myStringDate = strtotime('26-07-2019');
  
    $newDateFormat = date('m/d/Y',$myStringDate);
  
    print_r($newDateFormat);
  
?>

Read Also : How to Convert String Date to Date Format in PHP?

Output:

07/26/2019

Read Also : PHP AngularJS CRUD with Search and Pagination Example From Scratch

Thanks for read this, I hope it will you. You can also follow us on Facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →