Displaying the Date and Time on your website is one of those things that most people donβt really think about. We tend to stick with the default formatting for the publish date on post metadata. And, if we have time, weβll add the current year dynamically to the footer bar next to the copyright text.
However, understanding how to format the date and time comes in handy. It gives you the freedom of making a date more readable for users. For example, βOn Monday the 23rd of May, 2020β is a bit warmer (and more human) than minimal date displays like β5.23.20β. Although the latter does have its place. The same goes for formatting the current time on a website. Some sites may benefit from a 12hr display like β8:30pmβ while others (like military or medical sites) would rather a 24hr display like β20:30β.
Divi and WordPress give you a surprising amount of control over the date and time formatting available in PHP. In this tutorial, we are going to help you understand how to display, format, and style the date and time in Divi. Youβll be able to give blog posts a custom format for the publish date or even add a dynamic element to a call to action for a more personal touch (i.e. βHappy Monday! Check out our new deal.β).
Letβs get started!
- 1 Download a Date and Time Formatting Guide Divi Layout for FREE
- 2 Download For Free
- 3 You have successfully subscribed. Please check your email address to confirm your subscription and get access to free weekly Divi layout packs!
- 4 Available Format Characters for Displaying the Date and Time
- 5 Formatting the Date and Time with Divi
- 6 More Helpful Examples
- 7 Final Thoughts
Download a Date and Time Formatting Guide Divi Layout for FREE
To help get a jump on the date and time formatting in Divi, download this helpful Date and Time formatting Guide layout. It includes examples of each date/time format being used as dynamic content in a Divi text module so you can see first hand how each one functions on a live page.
To lay your hands on the date and time formatting guide, you will first need to download it using the button below. To gain access to the download you will need to subscribe to our newsletter by using the form below. As a new subscriber, you will receive even more Divi goodness and a free Divi Layout pack every Monday! If youβre already on the list, simply enter your email address below and click download. You will not be βresubscribedβ or receive extra emails.
To import the section layout to your Divi Library, navigate to the Divi Library.
Click the Import button.
In the portability popup, select the import tab and choose the download file from your computer.
Then click the import button.
Once done, the section layout will be available in the Divi Builder.
Letβs get to the tutorial, shall we?
Available Format Characters for Displaying the Date and Time
As mentioned before, Divi takes advantage of WordPressβ built-in date and time formatting. But before we get into how to format a date and time in Divi, it helps to understand the formatting characters available to us.
Below is a list of available format characters that can be used together (or combined) to create custom date and time formats. This will come in handy when experimenting with unique formats for date and time on your Divi site.
Date Formatting
DAY format characters
- d = Day of the month, 2 digits with leading zeros (β02β, β22β)
- D = Day of the month in three letters (βJunβ, βJulβ)
- l (lowercase βLβ) = Day of the week, the full word (βMondayβ, βTuesdayβ)
- N = ISO-8601 numeric day of the week (β1β for Monday and β7β for Sunday)
- S = suffix for the day of the month; use with j (βndβ, βstβ, βrdβ)
- w = Numeric day of the week (β0β for Sunday and β6β for Saturday)
- z = The day of the year, starting from 0 (ie. β173β or βthis is the 173rd day of the yearβ)
WEEK format character
- W = 26 (week number of year, weeks starting on Monday; ie. βthis is the 26th week of the yearβ)
MONTH format characters
- F = A full textual representation of a month (βJanuaryβ or βMarchβ)
- m = Numeric month, with leading zeros (June is displayed as β06β)
- M = Month in three letters (March is displayed as βMarβ)
- n = Numeric month, without leading zeros (June is displayed as β6β)
- t = Number of days in the given month (If June it would display β30β)
YEAR format characters
- Y = 2020 (4 digit numeric year; ie. β2020β)
- y = 20 (2 digit numeric year; ie. β20β)
Example Date Format Strings
- M j, Y = Jun 22, 2020
- F d, Y = June 22, 2020
- m/d/Y = 06/22/2020
- m.d.Y = 06.22.2020
- j M, Y = 22 Jun, 2020
- l, M d = Monday, Jun 22
- l, F jS, Y = Monday, June 22nd, 2020
- m Β· d Β· y = 06 Β· 22 Β· 20
Time Formatting
TIME format characters
- a = (lowercase βamβ or βpmβ)
- A = PM (uppercase βAMβ or βPMβ)
- g = Hour, 12-hour, without leading zeros (β1-12β)
- h = Hour, 12-hour, with leading zeros (β01-12β)
- G = Hour, 24-hour, without leading zeros (β0-23β)
- H = Hour, 24-hour, with leading zeros (β00-23β)
- i = 10 (Minutes, with leading zeros (β00-59β)
- s = 52 (Seconds, with leading zeros (β00-59β)
- T = Timezone (βCDTβ, βESTβ)
Example Time Format Strings
- g:i a = 4:10 pm
- g:i:s a = 4:10:52 pm
Date + Time Format Strings
- Y/m/d g:i:s A = 2020/06/22 4:10:52 PM
- M j, Y @ G:i = Jun 22, 2020 @ 16:10
Escaping Format Strings with β\β to Incorporate Additional Text/Characters
This is a really helpful trick for customizing the date and time display. Simply add β\β before each character/letter you want to include in the format string and that character will render as it would normally (outside of the string). So, β/T/h/eβ would render the word βTheβ in the format string instead of an actual date/time element like Timezone (βTβ) or hour (βhβ).
- D \a\t ga = Mon at 4pm
- \T\h\e dS \d\a\y \o\f F = The 22nd day of June
Formatting the Date and Time with Divi
Changing the Default Date Format Sitewide
If you want to change the default date and time format sitewide, WordPress has a built-in option for this. From your WordPress Dashboard, navigate to Settings > General. There you will see the option to change the default timezone, date format, and time format.
Divi actually uses these same default formats when you add a date or time using dynamic content with the Divi Builder (like post publish date and current date).
If you are using Diviβs default blog post layout (not a custom layout built with the Divi Builder), you can enter a custom date format string to be used for all of the blog posts sitewide. You can find the date format option by navigating to Divi > Theme Options and scroll down the page under the General tab.
Interestingly, you can even enter time format characters to display the time the post was published.
Using Diviβs Dynamic Content to Format and Display Date and Time
When using the Divi Builder, you have the option of adding the current date or the post publish date as dynamic content to any module. This is a great way to override the default date and time format on a case by case basis, as well as add custom styling the date/time text.
To add a post publish date or current date as dynamic content to your page in Divi, simply add a text module to the page.
Then select the dynamic content icon while hovering over the content box.
Once the dynamic date has been added to the content of the module, you can click to edit the dynamic date for more customization. These additional settings include the option to add before and after content to the date display as well as the option to customize the format of the date.
Diviβs Built-In Date Formats
Under the date format dropdown, you will find the following pre-made date formats you can select.
- M j, Y = Jun 22, 2020
- F d, Y = June 22, 2020
- m/d/Y = 06/22/2020
- m.d.Y = 06.22.2020
- j M, Y = 22 Jun, 2020
- l, M d = Monday, Jun 22
Adding a Custom Date/Time Format
To create a custom date/time format, select the custom option from the dropdown. Once you choose the custom option, you will have an input box available where you can work your magic by adding any combination of available format characters to create the perfect format string for the date, time, or both.
This same process can be used to add the current time or post publish time. Simply add the time formatting characters inside the Custom Date Format box.
After you have the content in place, you can use Diviβs built-in design settings, under the design tab of the text module, to customize the body text however you like. The dynamic date/time format will adopt the style of the body text.
More Helpful Examples
Copyright Year
Date and Time formatting comes in handy for creating a dynamic copyright year for the global footer of your Divi site. Here is a custom format you can use for displaying the copyright info with the dynamic year in a single text module.
Add the current date as dynamic content to a text module. Then edit the dynamic content with the following:
- Before: ©
- After: Company | All Rights Reserved.
- Custom Date Format:Y
Dynamic Call to Action
You can also add a dynamic date or time format (inline) to a call to action or heading on your Divi website. To do this, add a current date as dynamic content to a text module. Then update the following:
- Before:
<h1>It's
- After:
... <br>Time to Design!</h1>
- Custom Date Format: l β¦ \a\f\t\e\r g a
Notice that the h1 header is added to the element using html tags in the before and after inputs. The word βTuesdayβ is being displayed by the βlβ in the custom date format box, followed by the word βafterβ using the β\β to escape the format string. Then the βgβ and βaβ are used to display the β6 pmβ
You can then customize the h1 heading styles under the design tab.
Final Thoughts
Hopefully, this post has (and continues to be) a helpful guide for how to format the date and time in Divi. If you are like I was, your eyes have been opened to some surprising formatting options that you can achieve without a plugin and with custom code!
I look forward to hearing from you in the comments.
Cheers!
It would be really useful if you could add a date modified option to this
Hello, you wrote “When using the Divi Builder, you have the option of adding the current date or the post publish date as dynamic content to any module”. Not true. I have a post slider module. I can only add the page date but not the post publish date. How can I add the dynamic content to add post date? Thanks
This is really a bunch of information. I suggest that you read this info yourself and use it on DIVI
Why?
1) Each WP installation sets a standard format
2) In DIVI Options a standard date format is set as well
However in nearly all DIVI modules which are part of DIVI you have to set the default date format again because there these 2 settings are ignored and you have to define again again and again
I am sure you have heard your clients asking for using the user-set date format a hundred thousand times, but your ears are closed. Instead you give us lessons which we find in all PHP books or courses…
Please stop this non-user-friendly workflow – use the date format from either WP or DIVI options!!!
Well-said!