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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date column problem 2

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I am inserting records with PHP, and having a problem with MySql not getting the date in a Date field.

I am using this in the insert code:
$ORDD=date("F j, Y");

But when I look at the record after inserting, the field just show:
0000-00-00

My obvious thought is a date format issue. I could possibly cheat and make the column Varchar, but I will need to query dates later.

Any advice please, thanks
 
you need to insert the date in this format : 0000-00-00

so date("Y-m-d") really.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks very much, that gets entered. I presume when I recover the record again to show in a document I will have to break it up again to show m/d/y or maybe m/d and split y away for year searching??
 
You could analyse the date using either PHP or MySQL functions. MySQL functions include DATE_FORMAT which will format a date any way you want, YEAR to extract the year, EXTRACT to extract any part of a date, and so on.
 
Thanks Tony, that confirms I will treat the format as I want it when I extract it from the database. Will work that out when I get there. Wanting something like August 24, 2006. Have a star both for the help.
 
select date_format(curdate(), "%M %d, %Y");

change curdate() for your date_field.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top