Page 1 of 1

Them darn Dates

Posted: Tue Feb 04, 2003 6:42 am
by Deddog
Help, being so thick! But can’t sort it.

Want to rearrange a date inputted in ye old English:

dd/mm/yyyy

so that it goes into a mysql database as :

yyyy/mm/dd

this is my last attempt:

$Break ="/";
$DateArray = explode("/",$FirstDate);
$year = ($DateArray[2]);
$month = ($DateArray[1]);
$day = ($DateArray[0]);
$ReturnDate = ($year.$Break.$month.$Break.$day);
?><script> alert(<? print $ReturnDate ?>);</script> <?

The alert output is :

27.8194444444444444444444444443

I can only assume that it’s dividing each value. How can I get it to act as a puka sting and not an equation.

Thanks in advance.

Posted: Tue Feb 04, 2003 6:52 am
by twigletmac
The script is actually working - it's JavaScript that's doing the dividing not PHP - you need some single quotes around the printed variable from PHP. You could also shorten the script a little:

Code: Select all

<?php
$Break = '/'; 
$DateArray = array_reverse(explode('/',$FirstDate)); 
$ReturnDate = implode($Break, $DateArray);
?>
<script> alert('<?php print $ReturnDate ?>');</script>
Mac

excellent

Posted: Tue Feb 04, 2003 7:41 am
by Deddog
suberb!

Knew it was somit stupid!

Many thanks,

Lee.