Hi all,
I have a MySQL database that stores the DOB of people, amongst other details. I need the user to be able to input a date in the standard UK format: DD-MM-YYYY whereas the MySQL table stores it in the YYYY-MM-DD format. To test formatting etc, i setup two pages seperate from the tables to format the time.
Page 1:
<html>
<head></head.
<body bgcolor="#CCFFCC">
<form action="timetest2.php" method="post">
Please type in a date in the following format: YYYY-MM-DD: <input type="text" name="date1">
<br><input type="submit" value="Change!"></form>
</body>
</html>
Page 2:
<?php
echo("Date in current format: " . "$_POST[date1]");
$date2=date_format($_POST[date1],'%d/%m/%Y');
echo("Formatted Date is: " . "$date2");
?>
<form action="timetest.php" method="post">
<input type="submit" value="New Date">
</form>
As an example, when i input 2008-07-23 on the first place and click Change!, page 2 loads, it properly echos the current format date as 2008-07-23. However the line underneath i get this error:
Warning: date_format() expects parameter 1 to be DateTime, string given in /home/chilte/public_html/secure/timetest2.php on line 3
Followed by Formatted Date is:
..and a load of blank space. So theres obviously something wrong with the way i am using the date_format function. I have looked at many examples, and none of them need a DateTime input for it to work. Any ideas on how to get around this please?
Cheers in advance
James