Click to See Complete Forum and Search --> : date/time


moondance
08-28-2003, 06:09 AM
Is there anyway to reverse a datetime that has been generated by mysql?

When a user posts a form, mysql creates a datetime for it, which is then displayed back to the user as:

2003-08-27

is there any way to turn this around (27-08-2003)?

ta

pyro
08-28-2003, 07:26 AM
Sure thing...

<?PHP
$date = "2003-08-27";
$itms = preg_split("/-/",$date);
$date = $itms[2]."-".$itms[1]."-".$itms[0];
# this might be even better:
# $date = $itms[1]."-".$itms[2]."-".$itms[0];
echo $date;
?>

moondance
08-28-2003, 08:06 AM
That function works great, but I didn't explain myself properly.

The date displayed is in this format:

2003-08-27 09:23:34

Can the above method put it in something like:
27-08-2003, 09:23:34

Cheers

pyro
08-28-2003, 08:14 AM
Try this, then (which is also a bit cleaner)...

<?PHP
$timestamp = "2003-08-27 09:23:34";
list($date, $time) = preg_split("/\\s/",$timestamp);
list($year, $month, $day) = preg_split("/-/",$date);
$date = $day."-".$month."-".$year.", ".$time;
echo $date;
?>

Khalid Ali
08-28-2003, 08:15 AM
pyro has given a very good answer what you need is a little variation in the function,I'd suggest you to look at
String functions at php.net site (http://www.php.net/manual/en/ref.strings.php)

This will help you understand what he did and how little of a change it may require to make it work for you.

moondance
08-28-2003, 08:24 AM
Thats really superb, thanks for your efforts and quick replies.


:D :D :D

pyro
08-28-2003, 08:49 AM
Happy to help... :)