clock  Mon - Sun 8.00 AM - 8.00 PM
mail  edu@teknowize.com
fb
instagram
play store
pinterest

How to Convert String Date to Date Format in PHP

  Hariom Prajapati
  24 Jun 2022
  PHP
Imperial Advance Hero Image

How to Convert String Date to Date Format in PHP

In this tutorial we will learn that how to convert string date to date format in PHP.

Using below code we can convert string date to any date format like Y-m-d, m/d/Y, d-m-Y etc in php.

Here we will use date() function for convert string date into any date format in PHP.

We also take an example to convert date to string date in PHP.

Now follow below code to convert string date to date format in PHP.

 

1) Convert string date to date format in PHP

<?php
    $OurStringDate = "1564079400";
    date_default_timezone_set('Asia/Kolkata');
    $DateFormatFirst = date('m/d/Y', $OurStringDate);
    print_r($DateFormatFirst);
    echo "<br><br>";
    $DateFormatSecond = date('m-d-Y', $OurStringDate);
    print_r($DateFormatSecond);
    echo "<br><br>";
    $DateFormatThird = date('m/d/y', $OurStringDate);
    print_r($DateFormatThird);
?> 

 

Output

php

 

2) Convert date to string date and then convert to any date format in PHP

 <?php
 $OurStringDate = strtotime('17-11-2021'); //converting date to string date
    date_default_timezone_set('Asia/Kolkata');
    $DateFormatFirst = date('m/d/Y', $OurStringDate);
    print_r($DateFormatFirst);
    echo "<br><br>";
    $DateFormatSecond = date('m-d-Y', $OurStringDate);
    print_r($DateFormatSecond);
    echo "<br><br>";
    $DateFormatThird = date('m/d/y', $OurStringDate);
    print_r($DateFormatThird);
?> 

 

Output

php