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

Disable Product Pages in WooCommerce

Add the following code to your functions.php file to disable users from accessing product pages within WooCommerce: /* Remove Links to Access Product Pages */ remove_action( ‘woocommerce_before_shop_loop_item’, ‘woocommerce_template_loop_product_link_open’, 10 ); remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_product_link_close’, 5 ); /* Prevent Users from Accessing Product Pages by Displaying the 404 Page */ function prevent_access_to_product_page(){

Read More »

Tips For Setting Up An E-Commerce Store

Need some tips for setting up an e-Commerce store? Having an online shop, such as an e-Commerce store, can be both exciting and overwhelming. However, if you market it right, you can make a good income off of it. When web design companies build e-Commerce sites for their clients, there’s

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

Let's Get Some Info