logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > General
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 09-13-2007, 03:07 AM   #1
nanny
 
Join Date: Apr 2006
Posts: 290
Default I know this sounds strange but does anyone know how to update date in mysql?

Hi I have placed in the form
Code:
DATE_ADD(CURDATE(),INTERVAL 90 DAYS);
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?
nanny is offline   Reply With Quote
Old 09-13-2007, 05:40 AM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

please explain what your trying to do here
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 09-14-2007, 05:54 AM   #3
nanny
 
Join Date: Apr 2006
Posts: 290
Default

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.
nanny is offline   Reply With Quote
Old 09-14-2007, 06:10 AM   #4
nanny
 
Join Date: Apr 2006
Posts: 290
Default

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.
nanny is offline   Reply With Quote
Old 09-14-2007, 06:29 AM   #5
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

i have a function which i use to do this...

add the function in a seperate file and include the file in every page...
PHP Code:
 
function dateFormater($date){
 
// split date into components and strip delimiter "/ -"
// test to determin which way round the date is
$yy  substr($date64);
 
// detect if $yy contains just numbers
if(is_numeric($yy)){
 
$dd  substr($date02);
$mm substr($date32);
 
// build mysql format
$newDate $yy."-".$mm."-".$dd;
return 
$newDate;
 
}else{
 
$dd  substr($date82);
$mm substr($date52);
$yy  substr($date04);
 
// build display format
$newDate $dd."-".$mm."-".$yy;
return 
$newDate;
}
 

ok thats your function

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

PHP Code:
// 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
dateFormater($_POST['datefield']); 
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 09-19-2007, 12:11 AM   #6
nanny
 
Join Date: Apr 2006
Posts: 290
Default

great function thanks davidj
nanny is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:24 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com