Why is this date not being inserted correctly?

I'm doing a basic insert statement after having scraped the data from a webpage.

When I go to insert the date, I repeatedly get "0000-00-00."

I'm grabbing the data using getElementsByTagName and it prints as 12/04/2014. But when I go to insert it into the database, it's not processing it correctly.

I figured it had to be something related to the way I was attempting to insert a string when MySQL needed a date, so I did this:

$date=date("m/d/Y", strtotime($cols->item(0)->nodeValue));

I echo-ed it, just to make sure I was barking up the right tree, and it still goes into the database as 0000-00-00.

What am I missing?
brucegustPHP DeveloperAsked:
Who is Participating?
 
GaryConnect With a Mentor Commented:
Format the date the same as MySQL is expecting it

$date=date("Y/m/d", strtotime($cols->item(0)->nodeValue));

Open in new window

0
 
brucegustPHP DeveloperAuthor Commented:
Gary, you're the man!

Had to go back and put my $date dynamic within my insert statement within "' '", but once that was in place an exasperating scenario was remedied!

Rock on!
0
All Courses

From novice to tech pro — start learning today.