PHP date() function for common date formats

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…

close-up of a calendar
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:

1
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.:

1
$some_date = '2020-12-31';

PHP date() function format: Full month name, day, four-digit year

One common date format you see a lot of is the full month name followed by the 2-digit day of the month, then the four-digit year (E.g. September 12th, 2020).

Using a combination of format characters, we can get any date in that format like so:

1
echo date('F jS, Y', strtotime($some_date));

1
December 31st, 2020

Here are the individual format characters meanings:

  • F – Full-text month name.
  • j – One or two-digit day of the month where appropriate. No padding leading zeros.
  • S – Two-character suffix for a 2-digit day of the month.
  • Y – Four-digit year.

PHP date() function format: two-digit day, three-letter month abbreviation, four-digit year

Another prevalent date format you see is in the MM-Mon-YYYY manner (E.g. 12-Sep-2020). That one is easy as well:

1
echo date('d-M-Y', strtotime($some_date));

1
31-Dec-2020

Below is these specific format characters’ meaning:

  • d – A two-digit day of the month (including any padded leading zeros).
  • M – Three-letter abbreviation for a month.
  • Y – Four-digit year.

PHP date() function format: two-digit month, two-digit day, two-digit year

Likely the most common date format I see is the variant of, MM/DD/YY. Meaning: two-digit month, two-digit day, and two-digit year (E.g., 12/31/20). This specific format is perhaps the easiest to configure of all covered so far in the post:

1
echo date('m/d/y', strtotime($some_date));

1
12/31/20

The 3 character format specifiers for this date output are:

  • m – Month number with any padded leading zeros.
  • d – A two-digit day of the month (including any padded leading zeros).
  • y – Two-digit year.


Be sure and check out all of the available format characters from the PHP datetime format documentation. There are several to choose from and I am sure you can come up with whatever your formatting needs are for date values.


Like what you have read? See anything incorrect? Please comment below and thank you for reading!!!

A Call To Action!

Thank you for taking the time to read this post. I truly hope you discovered something interesting and enlightening. Please share your findings here, with someone else you know who would get the same value out of it as well.

Visit the Portfolio-Projects page to see blog post/technical writing I have completed for clients.



To receive email notifications (Never Spam) from this blog (“Digital Owl’s Prose”) for the latest blog posts as they are published, please subscribe (of your own volition) by clicking the β€˜Click To Subscribe!’ button in the sidebar on the homepage! (Feel free at any time to review the Digital Owl’s Prose Privacy Policy Page for any questions you may have about: email updates, opt-in, opt-out, contact forms, etc…)

Be sure and visit the “Best Of” page for a collection of my best blog posts.


Josh Otwell has a passion to study and grow as a SQL Developer and blogger. Other favorite activities find him with his nose buried in a good book, article, or the Linux command line. Among those, he shares a love of tabletop RPG games, reading fantasy novels, and spending time with his wife and two daughters.

Disclaimer: The examples presented in this post are hypothetical ideas of how to achieve similar types of results. They are not the utmost best solution(s). The majority, if not all, of the examples provided, are performed on a personal development/learning workstation-environment and should not be considered production quality or ready. Your particular goals and needs may vary. Use those practices that best benefit your needs and goals. Opinions are my own.

3 thoughts on “PHP date() function for common date formats

Hey thanks for commenting! Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.