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?
If the error is at the time of any calculation, double check that the values does not contains any comma(,). Values must be only in integer/ float format.
I ran into this same situation (in my case with a date value in a custom PHP field in a Drupal view), and what worked for me was using intval instead of strtotime to turn the value into an integer - because it basically was a timestamp, but in the form of a string rather than an integer. Obviously that won't be the case for everyone, but it might be worth a try.
You need to set the time zone using date_default_timezone_set().
Because you are passing a string as the second argument to the date function, which should be an integer.
Try strtotime which will Parse about any English textual datetime description into a Unix timestamp (integer):
This is an old question, but there is another subtle way this message can happen. It's explained pretty well here, in the docs.
Imagine this scenerio:
And
MyCustomExceptionHandler
is defined roughly like:This will actually trigger a new exception in the custom exception handler because the
Exception
class is expecting a number for the second parameter in its constructor, butPDOException
might have dynamically changed the return type of$e->getCode()
to a string.A workaround for this would be to define you custom exception handler like:
$_GET['start_date']
is not numeric is my bet, but an date format not supported bystrtotime
. You will need to re-format the date to a workable format for strtotime or use combination of explode/mktime.I could add you an example if you'd be kind enough to post the format you currently receive.