A non well formed numeric value encountered

Deviland picture Deviland · May 26, 2011 · Viewed 375.4k times · Source

I have a form that passes two dates (start and finish) to a PHP script that will add those to a DB. I am having problems validating this. I keep getting the following errors

A non well formed numeric value encountered

This is when I use the following

date("d",$_GET['start_date']);

But when I use the strtotime() function as advised by many sites I get a unix timestamp date of 1/1/1970. Any ideas how I can get the correct date?

Answer

DChaplin picture DChaplin · Oct 3, 2012

Because you are passing a string as the second argument to the date function, which should be an integer.

string date ( string $format [, int $timestamp = time() ] )

Try strtotime which will Parse about any English textual datetime description into a Unix timestamp (integer):

date("d", strtotime($_GET['start_date']));