Them darn Dates

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Deddog
Forum Commoner
Posts: 55
Joined: Thu Sep 26, 2002 6:05 am
Location: Brighton

Them darn Dates

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Deddog
Forum Commoner
Posts: 55
Joined: Thu Sep 26, 2002 6:05 am
Location: Brighton

excellent

Post by Deddog »

suberb!

Knew it was somit stupid!

Many thanks,

Lee.
Post Reply