Jump to content

Changing form date to MySQL date to insert into database


AdRock

Recommended Posts

I have a form where my admin user has to enter a date of an event.

He has entered the date in a UK format such as 25/11/07 but i need to convert into a SQL date so i can insert it into my MySQL database

How do i convert the date as it reads something really random when i display the date on the page
On my form I have a text filed called txtEvent

Here is the code I use to create the $event variable

[code]$event = $_POST['txtEvent'];[/code]

and this is the code to coonvert the date to SQl format

[code]$EventDate = date('Y/m/d', strtotime($event));[/code]

When i echo $EventDate it is screwing the date right up somehting like 12/04/2031
I have just tried messing around with this to try and convert a date but it is still not working properly

I put in 21/9/2006 and it returns 2007/09/09

[code]<?php
$event = $_POST['txtEvent'];
if (!isset($_POST['txtEvent'])) {
?>
<h2>Add a forthcoming event</h2>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
    <p>Please enter a date for the event.
    <input id="calendar" class="form" type="text" title="Please enter the event date" size="30" name="txtEvent"></p>
  <p>
    <input type="Submit" value="Submit"><input type="reset" value="Reset">
</form>

<?php
}
else
{
$event  = str_replace("-","/",$event);
$date = date('Y/m/d', strtotime($event));
echo $date;
}
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.