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

Transferring Large Files

Sometimes when you have a designer or developer work on a project, you may have to send over large files to them. It is difficult for some people to send large files, especially if they aren’t tech savvy. Some of these large files might be for some graphic design project,

Read More »

How To Disable HTML in WordPress Comments

If you don’t want users to post HTML in comments on your site, you can post the code below into your WordPress theme’s functions.php file: /* Disable Hyperlinks in WordPress Comments */ remove_filter(‘comment_text’, ‘make_clickable’, 9); add_filter(‘pre_comment_content’, ‘strip_comment_links’); function strip_comment_links($content) { global $allowedtags; $tags = $allowedtags; unset($tags[’a’]); $content = addslashes(wp_kses(stripslashes($content), $tags));

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