Jake
Jake

Reputation: 3486

convert one date format to another

I need help to convert a formatted date format as stated below:

How can I convert 2010-02-06 14:44:43 to dd/mm/yyyy

Thanks

Upvotes: 0

Views: 153

Answers (3)

vascowhite
vascowhite

Reputation: 18430

$date = new DateTime('2010-02-06 14:44:43');
echo $date->format('d/m/Y');

Output:-

06/02/2010

See the manual

Upvotes: 1

Mike Purcell
Mike Purcell

Reputation: 19999

Great place to start for this type of general information, php docs, specifically related to your date format question: https://www.php.net/manual/en/function.date.php

-- Edit --

Answer with substr() forced me to do the work... using substr() to format a date is not the best option as PHP has built-in functions for that.

var_dump(date('d/m/Y', strtotime('2010-02-06 14:44:43')));

Upvotes: 3

Indranil
Indranil

Reputation: 2471

Try this:

<?php
$time = strtotime('2010-02-06 14:44:43');
echo date('d/m/Y',$time);
?>

Upvotes: 0

Related Questions