Click to See Complete Forum and Search --> : text field with today date....
Alidad
11-16-2007, 11:05 PM
Hi,, i can't seemed to figure out about the date in the text field. I have two text fields, first text field is for currently date and second text field is exprie date in 30 days.
My question is that how to write in php when person load the page and automatic show the date in the both text field of currently date and expire date 3o days later in the second text field!
please help thanks.
AM
NogDog
11-16-2007, 11:25 PM
<input type="text" name="today" value="<?php echo date('m/d/Y') ;?>">
<input type="text" name="expires" value="<?php echo date('m/d/Y', strtotime('+ 30 days')) ;?>">
Alidad
11-24-2007, 09:50 AM
thank you so much for response but for some reason is not working when i tried to insert into the mysql database.
for sample on the text field showing 11/24/2007 and if i want to insert into the database, i got error message said "Incorrect datetime value: '11/24/2007' for column 'postdate' at row 1".
mysql for datatype for postdate is (datetime).
what did i missed!
please let me know thanks.
AM
NogDog
11-24-2007, 10:11 AM
You need to convert it into yyyy-mm-dd format, e.g.:
$sqlToday = date('Y-m-d', strtotime($_POST['today']));
$sqlExpires = date('Y-m-d', strtotime($_POST['expires']));
Note, however, that no validation has been done to check that the input dates are valid. Personally, I prefer to provide the user with separate <select> form elements for month, day, and year. Then I run the values through the checkdate (http://www.php.net/checkdate)() function. Then if they are valid I can concatenate them into the yyyy-mm-dd format form my query, using sprintf (http://www.php.net/sprintf)().