String date current date/time?

String date current date/time?

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

Stefan Bogdanescu

Founder & Senior Architect

PHP Date Formatting and String Conversion

You are currently using date("D M d, Y G:i") to generate a formatted timestamp. This function returns a string immediately upon execution. The confusion arises because you seem to believe that $date needs further conversion into a "string" type before it can be used in a message. In PHP, the date() function already returns a string value by default. You do not need to cast it using string($date), nor is that syntax valid in standard PHP; you would need the PhpString extension for such casting, which is not part of the core language and often unnecessary.

The core issue lies in your attempt to convert this formatted string back into a timestamp using strtotime(). When you run $today = strtotime($date);, you are asking PHP to parse the human-readable text "D M d, Y G:i" back into Unix time (seconds since epoch). While strtotime is powerful, it relies on specific formats and context. If the format string passed to date() includes day names or months that strtotime cannot unambiguously resolve without additional context, or if there are timezone mismatches between where the date was generated and where strtotime interprets it, you end up with unexpected results. The "weird numbers" you are seeing are likely timestamps representing dates far in the future or past, caused by parsing errors or timezone offsets.

If your goal is simply to send this formatted date in a message (e.g., via email, SMS, or API response), you should stop trying to convert it into an integer timestamp and then back again. The string returned by date() is already exactly what you need. You can pass $date directly into your message concatenation logic:

$message = "Current time is: " . $date;
echo $message;

This approach ensures the human-readable format remains intact without any risk of parsing errors or timezone drift occurring during an unnecessary conversion step.

However, if you specifically require a numeric timestamp (an integer) for calculations, database storage, or comparison logic, it is best to generate that from the current time directly, rather than converting from a formatted string. Using time() provides a reliable Unix timestamp without ambiguity:

$timestamp = time();
// Then format it only when you need the human-readable version
$formattedDate = date("D M d, Y G:i", $timestamp);

This pattern separates concerns effectively. You handle raw time logic with integers and presentation logic with formatted strings. Trying to bridge the gap between a specific string format and a timestamp using strtotime introduces fragility. If you need the current time specifically for the message, sticking to the initial date() output is the most robust solution.

In modern PHP development, particularly within frameworks like Laravel, this distinction is even more critical. When working with Eloquent models or carbon instances, you often have a dedicated method like $now->toDateTimeString('D M d, Y G:i') which handles the formatting internally while keeping the underlying time object intact for further manipulation.

Avoid relying on strtotime to reverse-engineer timestamps from custom date strings unless you are certain of the format's strict adherence to standard formats that strtotime recognizes universally. The safest path is to treat date() output as a final string product and use time() or Carbon instances when numerical precision is required for logic operations.

Our network