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.
Them darn Dates
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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:
Mac
Code: Select all
<?php
$Break = '/';
$DateArray = array_reverse(explode('/',$FirstDate));
$ReturnDate = implode($Break, $DateArray);
?>
<script> alert('<?php print $ReturnDate ?>');</script>