Hi, i want to change format of date .
This code i add in my register page....

if(!empty($_POST['dob'])&& !empty($_POST['mob'])&& !empty($_POST['yob'])) {
$yob = mysqli_real_escape_string($con,$_POST['yob']);
$mob = mysqli_real_escape_string($con,$_POST['mob']);
$dob= mysqli_real_escape_string($con,$_POST['dob']);
$date = mysqli_real_escape_string($con,"$yob-$mob-$mob");
$addtothedb="INSERT INTO login (Dateofbirth) VALUES ('". $date . "')";          

and when i get back data from db and date show me like this (yyyy-mm-dd).but i dont want to like this. i would like to have like this (dd-mm-yyyy)

2 Years
Discussion Span
Last Post by cereal


That's the format supported by the database, save it like this, then when your get the result set format as you prefer. You can do it directly at query level with the format_date() function:

or in PHP with the IntlDateFormatter class:

For this task I use a little class, that can can convert also to a more readable format and display the month name in the language you prefer. Here's the code:


    class Dtime extends IntlDateFormatter
        private $date;

        public function __construct($datetime = '', $pattern = 'd MMMM yyyy HH:mm', $locale = 'it')
            parent::__construct($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL);

            $this->date = new DateTime($datetime);

        public function get()
            return mb_convert_case(parent::format($this->date), MB_CASE_TITLE, "UTF-8");

By default the language is set to Italian, but this can changed, as the format, usage example:

$date = '2015-04-14 21:00';
$dt   = new Dtime($date, 'dd-MM-yyyy', 'it');
echo $dt->get();

Which returns 14-04-2015, the default setting:

$date = '2015-04-14 21:00';
$dt   = new Dtime($date);
echo $dt->get();


14 Aprile 2015 21:00

There are also other methods to format a date, you can use the DateTime class or the strtotime() function:


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.