-5

I little bit stuck in SQL datetime format, I'm using datetime format because of sorting reasons.

The issue come that MySQL expect date in yyyy-mm-dd hh:mm:ss format and I need in exactly the opposite dd-mm-yyyy. There is some way pass and get in different format using PHP? .

ArtiMann
  • 53
  • 10

2 Answers2

1

Try this should help:

$datedb = "2018-03-01 11:54:33";
$date = date('d-m-Y', strtotime($datedb));
echo $date; // will print 01-03-2018

And read about date() function of php: http://php.net/manual/en/function.date.php; https://www.w3schools.com/php/func_date_date.asp

Salim Ibrohimi
  • 1,351
  • 3
  • 17
  • 35
0

Use Strtotime.it Parse about any English textual datetime description into a Unix timestamp

$mydate = "27-12-2017";
$dbdate = date('Y-m-d', strtotime($mydate));
//OP 2017-12-27
TarangP
  • 2,711
  • 5
  • 20
  • 41