A non well formed numeric value encountered

A non well formed numeric value encountered

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

Stefan Bogdanescu

Founder & Senior Architect

A non well formed numeric value encountered

When you see the PHP warning A non well formed numeric value encountered, it usually indicates that the engine attempted a mathematical operation or string conversion on data that isn't what you expect. In your specific case, this happens when executing date("d", $_GET['start_date']). The issue isn't with the date() function itself; it is with how PHP handles the second argument when it receives a non-integer value.

The date() function expects its timestamp parameter to be an integer representing seconds since the Unix epoch. However, when you retrieve data via $_GET, PHP automatically treats these variables as strings unless explicitly cast otherwise. If your HTML form sends a date string like "2023-10-25" or even just empty space, PHP attempts to convert that string into a number to pass it to the function's internal logic. Since "2023-10-25" is not a valid integer representation, PHP triggers the warning and treats the value as 0.

This behavior is rooted in how PHP parses strings for numeric contexts. When you pass a non-numeric string to a function expecting an integer, PHP implicitly casts the string to a number. If the string starts with a digit (like "2023"), PHP might parse that part successfully but then encounter invalid characters (like "-10"), causing the conversion to fail or behave unexpectedly depending on the specific internal implementation of the function. In many cases, this results in the value being treated as 0, which leads to the wrong date being returned or a warning if the casting logic is strict enough to flag it.

The immediate fix is to ensure that the value passed to date() is explicitly converted to an integer before usage. You can achieve this by using the (int) cast operator:

$startTimestamp = (int)$_GET['start_date'];
$startDate = date('d', $startTimestamp);

By casting $start_date to an integer, you force PHP to handle the conversion explicitly. If the string is numeric, it works as expected. If it contains non-numeric characters like dashes or slashes, the cast will result in 0, which might not be what you want logically, but it prevents the warning and gives you control over how to handle invalid input.

However, relying on implicit casting for date validation is a fragile pattern. A more robust approach involves validating the format before attempting conversion. If your form sends dates in a standard ISO format (YYYY-MM-DD), you can use strtotime() or DateTime objects to handle the parsing safely:

$startStr = $_GET['start_date'] ?? '';
if (!empty($startStr) && strtotime($startStr)) {
    $startDate = date('d', strtotime($startStr));
} else {
    // Handle invalid date or empty input gracefully
    $startDate = 'Invalid';
}

Using strtotime() is generally more forgiving regarding input formats than direct casting. It attempts to parse a wide variety of date strings and returns a timestamp integer on success, or false on failure. Checking for false allows you to distinguish between valid dates (even if they represent the epoch) and completely malformed inputs.

If you are building larger applications where form handling is frequent, consider using a framework like Laravel. Laravel provides robust request validation helpers that can automatically cast input values and validate date formats against expected rules without manual casting logic. For example, defining a date rule in your validation array ensures the input matches a specific format before it reaches your business logic.

Ultimately, the warning you are seeing is PHP's way of telling you that it cannot reliably convert your input string into a timestamp using implicit rules. Explicitly handling the conversion or validating the input format first eliminates the ambiguity and prevents unexpected behavior when populating your database.

Our network