Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Date into mySQL 1

Status
Not open for further replies.

tlhawkins

Programmer
Joined
Dec 28, 2000
Messages
797
Location
US
I found several posts like this on the forum but none of them seemed to solve my problem...


What I need to do is enter a user entered date into a Date type field.

so my SQL looks like this:
$daterite = date ('Y-d-m', strtotime($_POST["EDate"]));
$sql = "insert into tblexpense (Expense, PayTypeKey, CustKey, ServiceKey, ExpTypeKey, EDate, EDesc) ".
" values(" . $_POST["Expense"] . "," . $_POST["PayTypeKey"]. "," . $_POST["CustKey"] . ", " .
$_POST["ServiceKey"] .", " . $_POST["ExpTypeKey"] . ",'". $daterite . "','". $_POST["EDesc"]. "')";

which creates a query like:
insert into tblexpense (Expense, PayTypeKey, CustKey, ServiceKey, ExpTypeKey, EDate, EDesc) values(25.50,1,0, 0, 1,'2004-21-04','just an expense')

it does insert...(no error) but then the date value is 11/30/1999 no matter what date was inserted.

I've been using the variable $daterite to try to get the corect format... I've tried at least two dozen ways.

Does anybody know what would work?
Thanks.

Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
Hmmm... good question... strange answer...

the actual date in the database is 0000-00-00. I format the date using:
date ('m/d/Y', strtotime($row[6]))

and that gives me 11/30/1999

I'm still confused...
does all of that make sense to you?
Thanks

Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
You must hand dates to MySQL as YYYY-MM-DD or YYYY/MM/DD. Although it will accept dates in other formats without error, the data value stored will be bad.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks,

That seems to have fixed it...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top