date() method, "A non well formed numeric value encountered" does not want to format a date passed in $_POST

date() method, "A non well formed numeric value encountered" does not want to format a date passed in $_POST

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

The date() Function Misunderstanding in Legacy PHP Environments

The error message "A non well formed numeric value encountered" is a classic symptom of a fundamental mismatch between what your code expects and what your form actually sends. In the scenario you are facing, the root cause isn't that $_POST['nextAppointmentDate'] contains an invalid string; it's that the date() function operates on a different data type than you assume.

The PHP documentation for date() is explicit: it expects either an integer timestamp or a boolean true. When you pass $_POST['nextAppointmentDate']—which var_dump reveals as the string "12-16-2013"—the function attempts to interpret that string as a Unix timestamp. Since "12-16-2013" is not a valid integer representation of seconds since the epoch, PHP triggers the notice and returns an empty string (or fails depending on error reporting levels).

The intuition that strtotime() might fix this is logical, but it leads to another specific failure mode. You observed that using date('Y-m-d', strtotime($_POST['nextAppointmentDate'])) resulted in "1969-12-31". This is not a formatting error; it is a date parsing error caused by the input format itself.

Why strtotime() Fails on "M-D-Y" Formats

The function strtotime() relies on a set of standard English phrases and recognizable patterns to parse dates. It handles formats like "2013-12-16" (ISO 8601), "Dec 16, 2013", or relative strings like "next Monday".

However, it does not natively recognize the format MM-DD-YYYY or DD-MM-YYYY unless specific context clues are present. When you pass "12-16-2013" to strtotime(), the parser looks for a month name (like "December") or an ISO standard. Finding neither, it defaults to the Unix epoch start date, which is January 1, 1970.

In the United States, the format is typically Month-Day-Year. So, 12-16-2013 translates to December 16th. In Europe and much of the rest of the world, it is Day-Month-Year, translating to June 16th (since month 16 doesn't exist, some parsers might fail entirely or behave unpredictably, but strtotime often defaults to epoch if confused).

Because strtotime() cannot disambiguate between "December" and "June" based solely on the hyphen-separated numbers without a known locale context, it likely interprets the input as invalid or defaults to the epoch, resulting in December 31st of year zero (1969-12-31 is essentially -1 day from the epoch start).

The Solution for PHP 5.2 Constraints

You mentioned that you are constrained to PHP 5.2. This is a significant limitation because DateTime classes and their constructors were introduced in PHP 5.2, but they require specific handling to avoid the "non well formed numeric" error when dealing with raw strings.

If you must stick with the procedural date() function and cannot upgrade your server to a version that supports DateTime::createFromFormat(), you have two reliable options:

Option 1: Use a Format String with DateTime

Even in PHP 5.2, the DateTime class exists. You can bypass strtotime entirely by explicitly telling the constructor how to parse the string. This is often more robust than relying on strtotime()'s guesswork.

// Explicitly define the format expected from your form
$aptnDate2 = DateTime::createFromFormat('m-d-Y', $_POST['nextAppointmentDate']);

if ($aptnDate2 && $aptnDate2->format('Y-m-d')) {
    // Successfully parsed
    echo $aptnDate2->format('Y-m-d');
} else {
    // Handle the case where parsing failed or format didn't match
    // You might want to handle 'd-m-Y' depending on your locale expectations
}

This approach removes the ambiguity of strtotime() and ensures that "12" is treated as a month, not a day. Note that in PHP 5.2, you must use the class name without the namespace prefix (it is in the global namespace).

Option 2: Stick to date() with Timestamp Conversion

If you absolutely cannot use object-oriented syntax or need to stay strictly procedural for legacy reasons, you must convert the string to a timestamp using a method that understands the format. Since strtotime fails on this specific string, you would technically need to parse it manually or upgrade your PHP version to use DateTime::createFromFormat and then call getTimestamp().

However, given your constraint of PHP 5.2, Option 1 is usually the path of least resistance because it leverages a class available in that version without requiring complex workarounds.

Best Practice for Legacy Systems

While upgrading from PHP 5.2 to PHP 7 or 8 would resolve these parsing headaches instantly, legacy systems often have dependencies that prevent immediate migration. In this context, explicit formatting is superior to implicit parsing. Always define the input format (m-d-Y vs d-m-Y) rather than relying on strtotime() to guess it. This prevents the "1969" epoch errors and eliminates the need for date() to receive a raw string in an unexpected guise.

Our network