1

This is my code below :

$startDate= str_replace('/', '-', $bhishi_date);
$startDate=strtotime($startDate);
$startDate= date('Y-m-d', strtotime($startDate))
  • You can use just the last cmd like `$startDate= date('Y-m-d', strtotime('10/05/2025'))`; – Simone Rossaini Sep 02 '21 at 11:30
  • 1
    Does this answer your question? [Converting string to Date and DateTime](https://stackoverflow.com/questions/6238992/converting-string-to-date-and-datetime) – KhorneHoly Sep 02 '21 at 11:30
  • But it is not working !!! – Parth Patel Sep 02 '21 at 11:33
  • 2
    `But it is not working`... yes it is - demo: http://sandbox.onlinephpfunctions.com/code/20fdc4d95f07a30c7c3e334c6731040f76624fe6. Adapted to your situation: http://sandbox.onlinephpfunctions.com/code/52154a75c2ebf8cc74f9e198d06902571d360e1b That's assuming of course that 10/05/2025 is supposed to be 5th October, and not 10th May. If it's the latter, the lesson from that is not to pass dates around in ambiguous formats. If you need to parse from a specific format, see https://www.php.net/manual/en/datetime.createfromformat.php – ADyson Sep 02 '21 at 11:48

3 Answers3

0

Try Below Code its help for you.

   $startDate= date('Y-m-d', strtotime($bhishi_date))
Dhaval Gol
  • 160
  • 10
0

You can use Carbon too:

$startDate = \Carbon\Carbon::parse('10/05/2025');
Rouhollah Mazarei
  • 3,969
  • 1
  • 14
  • 20
0

To deal with dates and times, I prefer to use the build-in DateTime class with which you can do everything in a consistent syntax.

$startDate = \DateTime::createFromFormat('d/m/Y', '10/05/2025')->format('Y-m-d');
//                  input format ---------^^^^^   output format ---------^^^^^
Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125