Hi I currently have date in database in this format:
11-7-2009
But I think I need to echo this in this format: 2009-11-07
There's probably a better way to do this, but this works:
<?php
$date = "11-7-2009"; // Date from database in MM-DD-YYY format
$date = explode("-", $date); // Split date into array of numbers
$time = mktime(0, 0, 0, $date[0], $date[1], $date[2]); // Convert date into timestamp
$modified_date = date('Y-m-d', $time); // Convert timestamp into YYYY-MM-DD format
?>
Alternative to Lsmjudoka's solution:
<?php
$a = '11-07-2009';
$b = explode('-', $a);
echo $b[2] .'-'. $b[0] .'-'. $b[1];
?>
Maybe I'm wrong but, in this case, I don't see any advantage in using mktime()
bye :)
This just did what I needed to do. Kudos!
<?php
$date = "11-7-2009"; // Date from database in MM-DD-YYY format
$date = explode("-", $date); // Split date into array of numbers
$time = mktime(0, 0, 0, $date[0], $date[1], $date[2]); // Convert date into timestamp
$modified_date = date('Y-m-d', $time); // Convert timestamp into YYYY-MM-DD format
?>
Hello All
Please check this Link.you find it Answers.
http://php.net/manual/en/function.date.php
Thanks
Or you could simply call this function
<?php
$date = '01/01/2003'; // OR CALL FROM DATABASE $date = $row['date'];
function changeDate($date)
{
$newdate = date('Y/m/d',strtotime($date));
return $newdate;
}
// TO CALL THE FUNCTION
echo changeDate($date);
?>
Hope it helps
@emhmk1
he can't use strtotime() because the date format is MM-DD-YYYY not DD-MM-YYYY
Here you can read the formats that strtotime() expects: http://www.php.net/manual/en/function.strtotime.php#91165
bye
@emhmk1
he can't use strtotime() because the date format is MM-DD-YYYY not DD-MM-YYYYHere you can read the formats that strtotime() expects: http://www.php.net/manual/en/function.strtotime.php#91165
bye
apologies, i didn't correctly read the request.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.