Search code examples
phpsymfony-3.2

Getting date from a string without time in php


I have to convert a string input to date "1990/07/22" to 22/07/1990 as date,My function is as follows as:

public function($date){
    $date_format_sec = strtotime($date);
    $date_of_birth = new \DateTime('@'.$date_format_sec);
}

It uploads date as 21/07/1990 since I didn't give time.How to get the exact date given as same as input.


Solution

  • You can format your date with php

    $formatedDate = $date_of_birth->format('d-m-Y');
    

    Documentation