View Full Version : I know this sounds strange but does anyone know how to update date in mysql?

09-13-2007, 03:07 AM
Hi I have placed in the form


as a hidden field in the expiry date field, but if I try to do the same again in the edit form - no luck, it seems to go to 1970 - odd.
I also tried php but I know it is mysql wanting it put into the database not echoing the date in 90 days etc.
I then tried using a javascript calendar to input into the formfield as YYYY-MM-DD but it still rejected it.
I need to renew dates on this.
Any suggestions?

09-13-2007, 05:40 AM
please explain what your trying to do here

09-14-2007, 05:54 AM
Hi I am wanting to add a date manually or via a popup calendar into my form.
Now I do use a date in my mysql table and I use your combo: onchange="document.forms[0].submit()
I have also found this great pop up calendar from Tiagra but any calendars I use don't input the date, all I get is 0000-00-00 which is an empty mysql date.
Any suggestions? I don't have a problem with placing DATE_ADD(CURDATE(), INTERVAL 90 DAY') and it will give me the correct date, however I am wanting to use a calendar if possible to give me the option of changing the date to either 3months, 6months or 12months till expiry.

09-14-2007, 06:10 AM
Now I have just found that if I put in manually 20080905 for 2008-09-05 now to get the calendar to do the same maybe?
Then I need to convert it to 05-09-2008 on my forms.

09-14-2007, 06:29 AM
i have a function which i use to do this...

add the function in a seperate file and include the file in every page...

function dateFormater($date){

// split date into components and strip delimiter "/ -"
// test to determin which way round the date is
$yy = substr($date, 6, 4);

// detect if $yy contains just numbers

$dd = substr($date, 0, 2);
$mm = substr($date, 3, 2);

// build mysql format
$newDate = $yy."-".$mm."-".$dd;
return $newDate;


$dd = substr($date, 8, 2);
$mm = substr($date, 5, 2);
$yy = substr($date, 0, 4);

// build display format
$newDate = $dd."-".$mm."-".$yy;
return $newDate;


ok thats your function

to call it just include the file then after do this...

// this will display the date correctly after you pull it out of the db
echo dateFormater($date);

// this will switch a date and prepare it for db format befor you insert it

09-19-2007, 12:11 AM
great function thanks davidj