What are some best practices for structuring and organizing PHP code when dealing with date manipulation and output?

When dealing with date manipulation and output in PHP, it is best practice to encapsulate date-related functions and logic within a separate class or set of functions to keep your code organized and maintainable. This allows for easier reuse of date-related functionality throughout your codebase and helps to avoid code duplication.

class DateHelper {
    public static function formatDate($date, $format = 'Y-m-d') {
        return date($format, strtotime($date));
    }

    public static function getCurrentDate() {
        return date('Y-m-d');
    }

    public static function addDaysToDate($date, $days) {
        return date('Y-m-d', strtotime($date . ' + ' . $days . ' days'));
    }
}