im trying to submit a dates to my database by using a jquery UI datepicker
but it seems to be entering the date into the database as 0000-00-00
The thing that im trying to achieve is a site where people can guess the date of an event happening and they use the datepicker to pick the date.
Ill also have a page that will display all the predictions but i want to display the dates like this example
Monday 11th August 2011
I also want to be able to display all the predictions for each month on their own pages
Is there something i have to do so change the way the date is sent to the DB so i can have it in the format that i want or do i have create separate columns for day month year??
I dont know what format jquery sends the date over as but entering the date into the db as YYYY-mm-dd wont cause you too many problems as there are functions in MYSQL itself that will let you format dates as you retrieve them.
Another option would be to store the information as a timestamp in the db. Simply work out what format jquery is sending the data as, break the data up and use it in mktime(). Then when you retrieve it from the db you can use the date() function to format it however you want.
$date="28/07/2011"; //check date format here before continuing. list($day,$month,$year)=explode('/',$date); $timestamp=mktime(0,0,0,$month,$day,$year); //insert into db. //retrieve from db at your leisure and simply $data=$timestamp; //would be your timestamp from db, have taken from above for simplicity echo date('l jS F Y',$data);
Basically, the data from jquery IS submitting to the database, however it is inserting 0000-00-00. This is because the date you are trying to insert is in the wrong format (i think).
Plan of action:
Go to the script that inserts the data into the database.
Put this line of php at the top:
PHP Code:
print_r($_POST); //or $_GET (depending on how the info is submitted)
This should output the information sent to that script. Find the date and post the format back on here. Ill rewrite the code i gave you above to match that format and then tell you where to put it
Sorry for the slow reply, had a bit of a mad weekend xD Anyway, what you need to do...in an appropriate place in the script you put the previous code in...
PHP Code:
$date=$_POST['date']; //or $_GET //check date format here before continuing. list($day,$month,$year)=explode('/',$date); $timestamp=mktime(0,0,0,$month,$day,$year); $final_date=date('Y-m-d',$timestamp);
then you can put $final_date into the db and it should work
Bookmarks