PHP date() function for common date formats

Josh Otwell
4 min readJan 13, 2021

Dates and time are everywhere. We live and operate based on date and time values. Work, sleep, or play — dates and time are always a deciding factor. Where on earth would we be without a calendar? I can tell you where I would be… Lost. Speaking of dates, there is not one universal format that I am aware of. People write them in all kinds of ways. If programming in PHP (such as yours truly) you may wish to format a date value in a particular manner. Using the PHP date() function, it’s super easy. In this blog post, I share 3 common date formats you can pull off with the PHP date() function…

Image by Andreas Lischka from Pixabay

PHP date() function: Syntax and overview

The date() function syntax is relatively straight-forward. Here is the example from the date() PHP documentation online:

date ( string $format [, int|null $timestamp = null ] ) : string

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time().

To keep things super-simple (just my speed), I’ll assign a variable the current date at the time of writing — New Year’s Eve — for me here in the U.S.:

$some_date = ‘2020–12–31’;

--

--

Josh Otwell

SQL/PHP | Photography | Technical Consultant. Sign-up for my free developer newsletter, OpenLampTech, here: openlamptech.substack.com