0

In a database, the date is stored like this: 14 May 2020 22:25

I was wondering, when reading this line from database, and change the output to this: 14-5-2020, is it possible to convert this easily? because sometimes i want to output 14 May 2020 22:25 and sometimes i want to output 14-5-2020. And if is possible, i only want to store 1 format in the database

john
  • 1,263
  • 5
  • 18

1 Answers1

1
<?php

$date = DateTime::createFromFormat('d M Y H:i', '14 May 2020 22:25');
echo $date->format('d-n-Y'); //14-5-2020

As mentioned in the comment by @Sammitch, you can use PHP DateTime Class to achieve this. You can format the Date and Time, once you create it. Be sure to check the format guide. Given below as link.

Useful Links:

Formatting DateTime in PHP

PHP DateTime

Harish ST
  • 1,475
  • 9
  • 23