Quick Answer
Format and manipulate dates.
Understanding the Issue
PHP's date functions provide powerful date formatting and calculation capabilities.
The Problem
This code demonstrates the issue:
Php
Error
// Need current date formatted
The Solution
Here's the corrected code:
Php
Fixed
// Current date/time
echo date("Y-m-d H:i:s"); // 2023-06-15 14:30:00
// Timezone handling
date_default_timezone_set("Europe/Amsterdam");
// DateTime object (recommended)
$now = new DateTime();
echo $now->format("l, F jS Y");
// Date arithmetic
$now->add(new DateInterval("P1D")); // Add 1 day
// Create from string
$date = DateTime::createFromFormat("d/m/Y", "15/06/2023");
Key Takeaways
Use DateTime class for complex date operations.