How to Convert String to Date in PHP?
When ever you need to convert string date to date formate like m/d/Y, Y-m-d, d-m-Y etc in php. we can easily convert string date specific date formate in php. we will use date() for converting string date to formate. we can also set timezone before convert string date to date in php example.
In this example i will give you very simple way to convert php string date to date formate. i gave you two example to understand how you will php string date format conversion. Also added output of that php example.
So, let's see both example. you can understand how it works.
Example:
<?php
$myStringDate = "1564079400";
date_default_timezone_set('Asia/Kolkata');
$newDateFormat = date('m/d/Y', $myStringDate);
print_r($newDateFormat);
?>
Output:
07/26/2019
Example 2:
<?php
$myStringDate = strtotime('26-07-2019');
$newDateFormat = date('m/d/Y',$myStringDate);
print_r($newDateFormat);
?>
Output:
07/26/2019
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- PHP Dropzone Display Existing Files from Server Example
- How to Upload and Resize Image in PHP?
- PHP MySQL Confirmation Before Delete Record using Ajax Example
- PHP Bootstrap Autocomplete Tokenfield using Ajax Example
- PHP MySQL Highcharts Chart Example
- PHP Import Excel File into MySQL Database Tutorial
- PHP CRUD Operation Using Ajax and JQuery Example
- Convert HTML to PDF in PHP with Dompdf Example
- How to Integrate Google Recaptcha with PHP Form?
- PHP JQuery Select2 Ajax Autocomplete Example
- How to Count Number of Files in Directory using PHP?
- How to Find Day Name from Specific Date in PHP?
- How to Get Difference Between Two Dates in Laravel?
- How to Remove Null Values from Array in PHP?