# Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (2024-01-15 25:00:00) at position 11 (2): Unexpected character in /var/www/app/src/Utils/DateParser.php on line 23

- **ID:** `php/date-timezone-invalid-format`
- **Domain:** php
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 92%

## Root Cause

Invalid date/time string format passed to DateTime constructor, often due to incorrect hour (e.g., 25), month (13), or malformed separators.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| PHP 8.0.30 | active | — | — |
| PHP 8.1.28 | active | — | — |
| PHP 8.2.16 | active | — | — |

## Workarounds

1. **Validate date strings before passing to DateTime: if (!strtotime($dateString)) { throw new InvalidArgumentException('Invalid date: ' . $dateString); }** (95% success)
   ```
   Validate date strings before passing to DateTime: if (!strtotime($dateString)) { throw new InvalidArgumentException('Invalid date: ' . $dateString); }
   ```
2. **Use DateTime::createFromFormat() with explicit format string to control parsing: $date = DateTime::createFromFormat('Y-m-d H:i:s', $input);** (90% success)
   ```
   Use DateTime::createFromFormat() with explicit format string to control parsing: $date = DateTime::createFromFormat('Y-m-d H:i:s', $input);
   ```

## Dead Ends

- **** — Setting date.timezone in php.ini to an invalid value like 'UTC-8' instead of 'America/New_York' does not fix parsing but changes the error message. (70% fail)
- **** — Using @suppress or error_control operator (@) hides the exception but does not fix the underlying invalid date string, leading to silent data corruption. (90% fail)
