Source: www.phparch.com

The PHP DateTime Class
As a developer, you're going to run into situations where you need to perform some kind of operation on a date or time. As an inexperienced developer, I had not invented here syndrome for these kinds of problems all the time.

In this article, we'll discuss how to use PHP's built-in DateTime classes to perform some basic operations on DateTime data.

Without any parameters, the DateTime class uses the date and time at the moment that that class was initialized.

namespace App\\Types; class DateTimeImmutable extends \\DateTimeImmutable { public function formatMySql(): string { return $this->format("Y-m-d H:i:s"); } public function formatUserFacing(): string { return $this->format("m/d/Y H:i"); }}
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners