Quick Resources: Date and Time in PHP

Smart Web Creative - Quick Resources: Date and Time in PHP

If you want to display the date and time in PHP, it can be somewhat confusing what letters to use to bring in those elements. Below is a list of all the PHP date and time options that you can use on your site:

OptionDescription
aam or pm
AAM or PM
BSwatch Internet time, a universal time scheme. More information is available at https://www.swatch.com
cISO 8601 date. This date is represented as YYYY-MM-DD. An uppercase T separates the date from the time. The time is represented as HH:MM:SS. The time zone is represented as an offset from Greenwich mean time (GMT) (only in PHP 5)
dDay of the month, two digits with leading zeros
DDay of the week in text, three letters
FMonth in text
gHour, 12-hour format without leading zeros
GHour, 24-hour format without leading zeros
hHour, 12-hour format with leading zeros
HHour, 24-hour format
iMinutes with leading zeros
I1 if Daylight Savings Time, 0 if not
jDay of the month without leading zeros
lDay of the week in text
L1, if it is a leap year, 0 if not
mMonth with leading zeros
MMonth in text three letters
nMonths without leading zeros
rRFC 822 formatted date
sSeconds with leading zeros
SEnglish ordinal suffix, textual, two characters
tNumber of days in the given month
TTime zone setting of this machine
USeconds since the epoch
wDay of the week, numeric (0 [Sunday])
yYear, two digits
YYear, four digits
zDay of the year
ZTime zone offset in seconds

To utilize these options in PHP, without using a plugin like Elementor, you could use the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN">
<head>
<title>Date and Time in PHP</title>
<meta Name="Author" Content="Smart Web Creative">
</head>
<body>
<p>
<?php

echo '<p>date("d-M-Y") =>', date("d-M-Y"), "</p>";
echo '<p>date("M/d/Y") =>', date("M/d/Y"), "</p>";
echo '<p>date("D ds M, Y h:i a") =>', date("D ds M, Y h:i a"), "</p>";
echo '<p>date("\T\h\e \\t\i\m\e \i\s: h:m a") =>', date("\T\h\e \\t\i\m\e \i\s: h:m a"), "</p>";
echo '<p>date("\T\o\d\a\y \i\s: l") =>', date("\T\o\d\a\y \i\s: l"), "</p>";

?>
</p>
</body>
</html>

Other Helpful Articles

What is Webmail?

What is webmail? Webmail is usually a free cloud-based email service that is set up on your hosting. You can use webmail by having a professional-looking email address such as, “[email protected]” and it’s usually at no additional cost. You can also have a professional-looking email with an email client such

Read More »

Setting Up WooCommerce Products

Having a WooCommerce store is a great way to sell things online. However, when setting up WooCommerce products, it’s important to note what you will need for adding products to your store. The following are items that are needed for each product: Product Title Product Description and/or Product Short Description

Read More »
Smart Web Creative - How To Grab a URL Parameter for an Elementor Form in a Popup

Elementor: How To Grab a URL Parameter for an Elementor Form in a Popup

Trying to find out how to grab a URL parameter for an Elementor form in a popup? You can use the Javascript code below within an HTML widget that is on your Elementor popup: <script type="text/javascript"> jQuery(function($){ //When Clicking Input Fields $(document).on(‘click’,’input’, function(event){ //Grab Current URL var urlstr = window.location.href;

Read More »

What Do You Need Done?:

(Please check all that apply)

Tell Us About You

Almost Done!

Let's Get Some Info

Let's Get Some Info

Let's Get Some Info

Let's Get Some Info

Let's Get Some Info