<!--
	This source file is part of the open source project
	ExpressionEngine User Guide (https://github.com/ExpressionEngine/ExpressionEngine-User-Guide)

	@link      https://expressionengine.com/
	@copyright Copyright (c) 2003-2021, Packet Tide, LLC. (https://packettide.com)
	@license   https://expressionengine.com/license Licensed under Apache License, Version 2.0
-->
<!DOCTYPE html>
<html lang="en" dir="ltr">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">

		<title>Date Variable Formatting — ExpressionEngine 5.4.2 Documentation</title>

		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" />

		<link rel="stylesheet" href="../_assets/default.min.css?v=3">

		<!-- Favicons -->
		<link rel="apple-touch-icon" sizes="180x180" href="../_assets/images/favicons/apple-touch-icon.png">
		<link rel="icon" type="image/png" sizes="32x32" href="../_assets/images/favicons/favicon-32x32.png">
		<link rel="icon" type="image/png" sizes="16x16" href="../_assets/images/favicons/favicon-16x16.png">
		<link rel="manifest" href="../_assets/images/favicons/site.webmanifest">
		<link rel="mask-icon" href="../_assets/images/favicons/safari-pinned-tab.svg" color="#2e6abd">
		<link rel="shortcut icon" href="../_assets/images/favicons/favicon.ico">
		<meta name="msapplication-TileColor" content="#2e6abd">
		<meta name="msapplication-config" content="../_assets/images/favicons/browserconfig.xml">
		<meta name="theme-color" content="#ffffff">

		<style>.sidebar-toc { visibility: hidden; }</style>
		<noscript><style>.sidebar-toc { visibility: visible; }</style></noscript>
	</head>
	<body>

		<div class="header">
			<div class="header-content">
				<a href="https://docs.expressionengine.com/latest" class="header-logo"><img src="../_assets/images/ee-logo-white.svg" alt=""></a>
				<a href="https://docs.expressionengine.com/latest" class="header-title">ExpressionEngine Docs</a>

				<nav>
					<a href="https://u.expressionengine.com" class="hide font-monospace">{ee:u}</a>
					<a href="https://expressionengine.com/forums" class="hide">Forums</a>

					<div class="version-button-wrapper">
					<div class="dropdown">
							<a class="" href="#">v5<span class="i-arrow-down"></span></a>
							<div class="dropdown-menu">
								<div class="dropdown-menu-inner">
									<a href="https://docs.expressionengine.com/latest/">v6</a>
									<a class="active" href="https://docs.expressionengine.com/v5/">v5</a>
									<a href="https://docs.expressionengine.com/v4/">v4</a>
									<a href="https://docs.expressionengine.com/v3/">v3</a>
									<a href="https://docs.expressionengine.com/v2/">v2</a>
									<a href="https://docs.expressionengine.com/v1/">v1</a>
								</div>
							</div>
						</div>
						<a href="https://docs.expressionengine.com/downloads/v5" class="download-button"><img src="../_assets/images/download.svg" alt=""></a>
					</div>
				</nav>

				<div class="hamburger mobile-menu-button" onclick="toggleMobileMenu();">
					<span></span><span></span><span></span>
				</div>
			</div>
		</div>

		<div class="sidebar-container">
			<div class="sidebar">
				<div class="sidebar-search">
				<input type="text" class="search-input" id="docsearch-input" name="search" placeholder="Search">
					<!-- <div class="sidebar-sponsor">
						<p>Sponsored By:</p><img src="" alt="">
					</div> -->
				</div>

				<div class="sidebar-toc">
					<ul><li  class=""><a href="../index.html">Welcome</a></li><li  class=""><a >Installation & Updates</a><ul><li  class=""><a href="../installation/requirements.html">System Requirements</a></li><li  class=""><a href="../installation/installation.html">Installation</a></li><li  class=""><a href="../installation/best-practices.html">Best Practices</a></li><li  class=""><a href="../installation/updating.html">Updating</a></li><li  class=""><a href="../installation/changelog.html">Change Log</a></li></ul></li><li  class=""><a >Getting Started</a><ul><li  class=""><a href="../getting-started/the-big-picture.html">The Big Picture</a></li><li  class=""><a href="../getting-started/ten-minute-primer.html">10 Minute Primer</a></li></ul></li><li  class=""><a >General Information</a><ul><li  class=""><a href="../general/url-structure.html">URL Structure</a></li><li  class=""><a href="../general/404pages.html">404 Pages</a></li><li  class=""><a href="../general/database-backup.html">Backing Up Your Site</a></li><li  class=""><a href="../general/moving.html">Moving to Another Server</a></li><li  class=""><a href="../general/gdpr.html">GDPR Compliance</a></li><li  class=""><a href="../general/cookies.html">Cookies</a></li><li  class=""><a href="../general/date-localization.html">Date Localization</a></li><li  class=""><a href="../general/languages.html">Language Packs</a></li><li  class=""><a href="../general/system-configuration-overrides.html">System Config Overrides</a></li><li  class=""><a href="../general/text-formatting.html">Text Formatting</a></li><li  class=""><a href="../general/converting-to-innodb.html">Converting to InnoDB</a></li><li  class=""><a href="../general/bbcode.html">BBCode Reference</a></li><li  class=""><a href="../general/reserved-words.html">Reserved Words</a></li><li  class=""><a href="../general/member-import-xml-format.html">Member XML Format</a></li></ul></li><li  class="active"><a >Templates</a><ul><li  class=""><a href="../templates/overview.html">Overview</a></li><li  class=""><a href="../templates/language.html">Template Language</a></li><li  class=""><a href="../templates/conditionals.html">Conditional Tags</a></li><li  class=""><a href="../templates/embedding.html">Embedding Templates</a></li><li  class=""><a href="../templates/layouts.html">Template Layouts</a></li><li  class=""><a href="../templates/partials.html">Template Partials</a></li><li  class=""><a href="../templates/variable.html">Template Variables</a></li><li  class=""><a >Global Template Variables</a><ul><li  class=""><a href="../templates/globals/single-variables.html">Single Global Variables</a></li><li  class=""><a href="../templates/globals/stylesheet.html">Linking to Stylesheets</a></li><li  class=""><a href="../templates/globals/url-segments.html">URL Segment Variables</a></li><li  class=""><a href="../templates/globals/consent.html">Consent Variables</a></li><li  class=""><a href="../templates/globals/path.html">Path Variables</a></li><li  class=""><a href="../templates/globals/preload-replacement.html">Preload Text Replacements</a></li></ul></li><li  class=""><a href="../templates/variable-modifiers.html">Variable Modifiers</a></li><li data-active-page="true" class="active"><a href="../templates/date-variable-formatting.html">Date Variable Formatting</a></li><li  class=""><a href="../templates/routes.html">Template Routes</a></li><li  class=""><a href="../templates/pagination.html">Pagination</a></li><li  class=""><a href="../templates/engine.html">The Template Engine</a></li></ul></li><li  class=""><a >Channels</a><ul><li  class=""><a href="../channels/entries.html">Entries Tag</a></li><li  class=""><a href="../channels/info.html">Channel Information Tag</a></li><li  class=""><a href="../channels/entry-linking.html">Next/Previous Entries</a></li><li  class=""><a href="../channels/entry-spanning.html">Spanning Across Pages</a></li><li  class=""><a href="../channels/entry-tracking.html">Entry Views Tracking</a></li><li  class=""><a href="../channels/dynamic-parameters.html">Dynamic Parameters</a></li><li  class=""><a href="../channels/categories.html">Categories Tag</a></li><li  class=""><a href="../channels/category-archive.html">Category Archive Tag</a></li><li  class=""><a href="../channels/category-heading.html">Category Heading Tag</a></li><li  class=""><a href="../channels/archive-months.html">Archive Month Links</a></li><li  class=""><a href="../channels/sets.html">Channel Sets</a></li><li  class=""><a href="../channels/calendar.html">Calendar Tag</a></li><li  class=""><a >Channel Form</a><ul><li  class=""><a href="../channels/channel-form/overview.html">Channel Form Tag</a></li><li  class=""><a href="../channels/channel-form/examples.html">Examples</a></li><li  class=""><a href="../channels/channel-form/inputs.html">Form Inputs</a></li><li  class=""><a href="../channels/channel-form/fields.html">Other Fields</a></li><li  class=""><a href="../channels/channel-form/status.html">Status Selection</a></li><li  class=""><a href="../channels/channel-form/categories.html">Category Selection</a></li><li  class=""><a href="../channels/channel-form/development.html">Development</a></li></ul></li></ul></li><li  class=""><a >Comments</a><ul><li  class=""><a href="../comment/overview.html">Overview</a></li><li  class=""><a href="../comment/entries.html">Entries Tag</a></li><li  class=""><a href="../comment/form.html">Submission Form</a></li><li  class=""><a href="../comment/subscriptions.html">Subscriptions</a></li><li  class=""><a href="../comment/control-panel.html">Control Panel</a></li></ul></li><li  class=""><a >Add-Ons</a><ul><li  class=""><a href="../add-ons/overview.html">Overview</a></li><li  class=""><a href="../add-ons/blacklist.html">Blacklist / White List</a></li><li  class=""><a href="../add-ons/consent.html">Consent</a></li><li  class=""><a href="../add-ons/email.html">Email</a></li><li  class=""><a href="../add-ons/emoji.html">Emoji</a></li><li  class=""><a href="../add-ons/file.html">File</a></li><li  class=""><a >Discussion Forum</a><ul><li  class=""><a href="../add-ons/forum/index.html">Overview</a></li><li  class=""><a href="../add-ons/forum/setup.html">Setup</a></li><li  class=""><a href="../add-ons/forum/boards.html">Boards</a></li><li  class=""><a href="../add-ons/forum/themes.html">Themes</a></li><li  class=""><a href="../add-ons/forum/global-variables.html">Global Variables</a></li><li  class=""><a href="../add-ons/forum/user-management.html">User Management</a></li><li  class=""><a href="../add-ons/forum/channel-forum.html">Associating Channel Entries with Forum Topics</a></li><li  class=""><a href="../add-ons/forum/recent-topics.html">Recent Forum Topics</a></li><li  class=""><a href="../add-ons/forum/signatures.html">Signatures and Avatars</a></li><li  class=""><a href="../add-ons/forum/helper.html">Helper</a></li><li  class=""><a href="../add-ons/forum/other-features.html">Other Features</a></li></ul></li><li  class=""><a href="../add-ons/http-header.html">HTTP Header</a></li><li  class=""><a href="../add-ons/ip-to-nation.html">IP to Nation</a></li><li  class=""><a href="../add-ons/metaweblog-api.html">Metaweblog API</a></li><li  class=""><a href="../add-ons/moblog.html">Moblog</a></li><li  class=""><a href="../add-ons/pages.html">Pages</a></li><li  class=""><a href="../add-ons/query.html">Query</a></li><li  class=""><a href="../add-ons/rss.html">RSS</a></li><li  class=""><a href="../add-ons/rss-parser.html">RSS Parser</a></li><li  class=""><a href="../add-ons/rte.html">Rich Text Editor</a></li><li  class=""><a >Search</a><ul><li  class=""><a href="../add-ons/search/index.html">Overview</a></li><li  class=""><a href="../add-ons/search/simple.html">Simple Form Tag</a></li><li  class=""><a href="../add-ons/search/advanced.html">Advanced Form Tag</a></li><li  class=""><a href="../add-ons/search/results.html">Displaying Results</a></li></ul></li><li  class=""><a >Simple Commerce</a><ul><li  class=""><a href="../add-ons/simple-commerce/index.html">Overview</a></li><li  class=""><a href="../add-ons/simple-commerce/control-panel.html">Control Panel</a></li><li  class=""><a href="../add-ons/simple-commerce/email-templates.html">Email Templates</a></li><li  class=""><a href="../add-ons/simple-commerce/ipn.html">Instant Payment Notification</a></li><li  class=""><a href="../add-ons/simple-commerce/items.html">Managing Store Items</a></li><li  class=""><a href="../add-ons/simple-commerce/paypal-settings.html">PayPal Settings</a></li><li  class=""><a href="../add-ons/simple-commerce/purchases.html">Managing Store Purchases</a></li></ul></li><li  class=""><a href="../add-ons/spam.html">Spam</a></li><li  class=""><a href="../add-ons/statistics.html">Statistics</a></li><li  class=""><a href="../add-ons/emoticon.html">Emoticon (Deprecated)</a></li></ul></li><li  class=""><a >Fieldtypes</a><ul><li  class=""><a href="../fieldtypes/overview.html">Overview</a></li><li  class=""><a href="../fieldtypes/date.html">Date</a></li><li  class=""><a href="../fieldtypes/duration.html">Duration</a></li><li  class=""><a href="../fieldtypes/email-address.html">Email Address</a></li><li  class=""><a href="../fieldtypes/file.html">File</a></li><li  class=""><a href="../fieldtypes/file-grid.html">File Grid</a></li><li  class=""><a href="../fieldtypes/fluid.html">Fluid</a></li><li  class=""><a href="../fieldtypes/grid.html">Grid</a></li><li  class=""><a href="../fieldtypes/relationships.html">Relationships</a></li><li  class=""><a href="../fieldtypes/rte.html">Rich Text Editor</a></li><li  class=""><a href="../fieldtypes/select.html">Checkboxes, Radio Buttons, Select, Multiselect</a></li><li  class=""><a href="../fieldtypes/text.html">Text Input</a></li><li  class=""><a href="../fieldtypes/textarea.html">Textarea</a></li><li  class=""><a href="../fieldtypes/toggle.html">Toggle</a></li><li  class=""><a href="../fieldtypes/url.html">URL</a></li></ul></li><li  class=""><a href="../member/index.html">Member Management</a></li><li  class=""><a >Control Panel</a><ul><li  class=""><a href="../control-panel/index.html">The Control Panel</a></li><li  class=""><a href="../control-panel/overview.html">CP Overview</a></li><li  class=""><a href="../control-panel/create.html">Create</a></li><li  class=""><a href="../control-panel/channels.html">Channels</a></li><li  class=""><a href="../control-panel/entry-manager.html">Entry Manager</a></li><li  class=""><a href="../control-panel/file-manager.html">File Manager</a></li><li  class=""><a href="../control-panel/field-manager.html">Field Manager</a></li><li  class=""><a href="../control-panel/member-manager.html">Member Manager</a></li><li  class=""><a href="../control-panel/member-profile.html">Member Profile</a></li><li  class=""><a href="../control-panel/template-manager.html">Template Manager</a></li><li  class=""><a href="../control-panel/addons-manager.html">Add-On Manager</a></li><li  class=""><a href="../control-panel/categories.html">Categories</a></li><li  class=""><a href="../control-panel/utilities.html">Utilities</a></li><li  class=""><a href="../control-panel/system-logs.html">System Logs</a></li><li  class=""><a >System Settings</a><ul><li  class=""><a href="../control-panel/settings/index.html">Overview</a></li><li  class=""><a href="../control-panel/settings/general.html">General Settings</a></li><li  class=""><a href="../control-panel/settings/avatars.html">Avatar</a></li><li  class=""><a href="../control-panel/settings/captcha.html">CAPTCHA</a></li><li  class=""><a href="../control-panel/settings/comments.html">Comment</a></li><li  class=""><a href="../control-panel/settings/content-design.html">Content & Design</a></li><li  class=""><a href="../control-panel/settings/consents.html">Consents</a></li><li  class=""><a href="../control-panel/settings/debug-output.html">Debugging & Output</a></li><li  class=""><a href="../control-panel/settings/email.html">Outgoing Email</a></li><li  class=""><a href="../control-panel/settings/hit-tracking.html">Hit Tracking</a></li><li  class=""><a href="../control-panel/settings/members.html">Member</a></li><li  class=""><a href="../control-panel/settings/messages.html">Messaging</a></li><li  class=""><a href="../control-panel/settings/security-privacy.html">Security & Privacy</a></li><li  class=""><a href="../control-panel/settings/template.html">Template</a></li><li  class=""><a href="../control-panel/settings/throttling.html">Access Throttling</a></li><li  class=""><a href="../control-panel/settings/urls.html">URL and Path</a></li><li  class=""><a href="../control-panel/settings/word-censor.html">Word Censorship</a></li><li  class=""><a href="../control-panel/settings/html-buttons.html">HTML Buttons</a></li><li  class=""><a href="../control-panel/settings/menu-manager.html">Menu Manager</a></li></ul></li><li  class=""><a href="../control-panel/footer.html">CP Footer</a></li></ul></li><li  class=""><a >Security</a><ul><li  class=""><a href="../security/general-tips.html">Tips</a></li><li  class=""><a href="../security/captchas.html">Captchas</a></li><li  class=""><a href="../security/spam-protection.html">Spam Protection</a></li></ul></li><li  class=""><a >Optimization</a><ul><li  class=""><a href="../optimization/caching.html">Caching and Performance</a></li><li  class=""><a href="../optimization/handling-extreme-traffic.html">Handling Extreme Traffic</a></li><li  class=""><a href="../optimization/throttling.html">Throttling</a></li><li  class=""><a href="../optimization/new-relic.html">New Relic Performance Monitoring</a></li></ul></li><li  class=""><a >Multiple Sites</a><ul><li  class=""><a href="../msm/overview.html">Overview</a></li><li  class=""><a href="../msm/code.html">Variables and Parameter</a></li></ul></li><li  class=""><a >Troubleshooting</a><ul><li  class=""><a href="../troubleshooting/general.html">General</a></li><li  class=""><a href="../troubleshooting/installation.html">Installation</a></li><li  class=""><a href="../troubleshooting/templates.html">Templates</a></li><li  class=""><a href="../troubleshooting/control-panel.html">Control Panel</a></li><li  class=""><a href="../troubleshooting/channels-and-entries.html">Channels and Entries</a></li><li  class=""><a href="../troubleshooting/email.html">Email</a></li><li  class=""><a href="../troubleshooting/simple-commerce-module.html">Simple Commerce Module</a></li><li  class=""><a href="../troubleshooting/error-messages.html">Error Messages</a></li></ul></li><li  class=""><a >Add-On Development</a><ul><li  class=""><a href="../development/addon-setup-php-file.html">The addon.setup.php File</a></li><li  class=""><a href="../development/plugins.html">Plugins</a></li><li  class=""><a href="../development/modules.html">Modules</a></li><li  class=""><a href="../development/extensions.html">Extensions</a></li><li  class=""><a >Extension Hooks</a><ul><li  class=""><a >Global</a><ul><li  class=""><a href="../development/extension-hooks/global/core.html">Core Library</a></li><li  class=""><a href="../development/extension-hooks/global/email.html">Email Library</a></li><li  class=""><a href="../development/extension-hooks/global/filemanager.html">Filemanager Library</a></li><li  class=""><a href="../development/extension-hooks/global/functions.html">Functions Library</a></li><li  class=""><a href="../development/extension-hooks/global/grid.html">Grid Fieldtype</a></li><li  class=""><a href="../development/extension-hooks/global/input.html">Input Library</a></li><li  class=""><a href="../development/extension-hooks/global/member-model.html">Legacy Member Model</a></li><li  class=""><a href="../development/extension-hooks/global/output.html">Output Library</a></li><li  class=""><a href="../development/extension-hooks/global/pagination.html">Pagination Library</a></li><li  class=""><a href="../development/extension-hooks/global/relationships.html">Relationships Fieldtype</a></li><li  class=""><a href="../development/extension-hooks/global/session.html">Session Library</a></li><li  class=""><a href="../development/extension-hooks/global/template.html">Template Library</a></li><li  class=""><a href="../development/extension-hooks/global/text-helper.html">Text Helper</a></li><li  class=""><a href="../development/extension-hooks/global/typography.html">Typography Library</a></li></ul></li><li  class=""><a >API Libraries</a><ul><li  class=""><a href="../development/extension-hooks/api/channel-fields.html">Channel Fields API</a></li><li  class=""><a href="../development/extension-hooks/api/template-structure.html">Template Structure API</a></li></ul></li><li  class=""><a >Control Panel</a><ul><li  class=""><a href="../development/extension-hooks/cp/admin-content.html">Admin Content Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/css.html">CSS Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/design.html">Design Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/javascript.html">Javascript Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/login.html">Login Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/members.html">Members Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/menu.html">Control Panel Menu</a></li><li  class=""><a href="../development/extension-hooks/cp/myaccount.html">My Account Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/publish.html">Publish Controller</a></li></ul></li><li  class=""><a >Models</a><ul><li  class=""><a href="../development/extension-hooks/model/category-field.html">CategoryField Model</a></li><li  class=""><a href="../development/extension-hooks/model/category-group.html">CategoryGroup Model</a></li><li  class=""><a href="../development/extension-hooks/model/category.html">Category Model</a></li><li  class=""><a href="../development/extension-hooks/model/channel.html">Channel Model</a></li><li  class=""><a href="../development/extension-hooks/model/channel-entry.html">Channel Entry Model</a></li><li  class=""><a href="../development/extension-hooks/model/channel-field-group.html">ChannelFieldGroup Model</a></li><li  class=""><a href="../development/extension-hooks/model/channel-field.html">ChannelField Model</a></li><li  class=""><a href="../development/extension-hooks/model/channel-form-settings.html">ChannelFormSettings Model</a></li><li  class=""><a href="../development/extension-hooks/model/channel-layout.html">ChannelLayout Model</a></li><li  class=""><a href="../development/extension-hooks/model/comment.html">Comment Model</a></li><li  class=""><a href="../development/extension-hooks/model/file.html">File Model</a></li><li  class=""><a href="../development/extension-hooks/model/template-global-variable.html">GlobalVariable Model</a></li><li  class=""><a href="../development/extension-hooks/model/member-field.html">MemberField Model</a></li><li  class=""><a href="../development/extension-hooks/model/member-group.html">MemberGroup Model</a></li><li  class=""><a href="../development/extension-hooks/model/member.html">Member Model</a></li><li  class=""><a href="../development/extension-hooks/model/site.html">Site Model</a></li><li  class=""><a href="../development/extension-hooks/model/template-snippet.html">Snippet Model</a></li><li  class=""><a href="../development/extension-hooks/model/template-specialty-template.html">SpecialityTemplate Model</a></li><li  class=""><a href="../development/extension-hooks/model/status.html">Status Model</a></li><li  class=""><a href="../development/extension-hooks/model/template-group.html">TemplateGroup Model</a></li><li  class=""><a href="../development/extension-hooks/model/template-route.html">TemplateRoute Model</a></li><li  class=""><a href="../development/extension-hooks/model/template.html">Template Model</a></li></ul></li><li  class=""><a >Modules</a><ul><li  class=""><a href="../development/extension-hooks/module/channel.html">Channel Module</a></li><li  class=""><a href="../development/extension-hooks/module/channel-form.html">Channel Form</a></li><li  class=""><a href="../development/extension-hooks/module/comment.html">Comment Module</a></li><li  class=""><a href="../development/extension-hooks/module/email.html">Email Module</a></li><li  class=""><a href="../development/extension-hooks/module/forum.html">Forum Module</a></li><li  class=""><a href="../development/extension-hooks/module/member.html">Member Module</a></li><li  class=""><a href="../development/extension-hooks/module/member-auth.html">Member Module Authorization</a></li><li  class=""><a href="../development/extension-hooks/module/member-register.html">Member Module Registration</a></li><li  class=""><a href="../development/extension-hooks/module/member-settings.html">Member Module Settings</a></li><li  class=""><a href="../development/extension-hooks/module/search.html">Search Module</a></li><li  class=""><a href="../development/extension-hooks/module/simple-commerce.html">Simple Commerce Module</a></li><li  class=""><a href="../development/extension-hooks/module/wiki.html">Wiki Module</a></li></ul></li></ul></li><li  class=""><a href="../development/fieldtypes.html">Fieldtypes</a></li><li  class=""><a href="../development/architecture.html">Architecture</a></li><li  class=""><a >Services</a><ul><li  class=""><a href="../development/services/addon.html">Addon Service</a></li><li  class=""><a href="../development/services/alert.html">CP/Alert Service</a></li><li  class=""><a href="../development/services/config.html">Config Service</a></li><li  class=""><a href="../development/services/consent.html">Consent Service</a></li><li  class=""><a href="../development/services/cookie.html">Cookie</a></li><li  class=""><a href="../development/services/csv.html">CSV Library</a></li><li  class=""><a href="../development/services/encrypt.html">Encrypt Service</a></li><li  class=""><a href="../development/services/event.html">Event Service</a></li><li  class=""><a href="../development/services/filepicker.html">CP/FilePicker Service</a></li><li  class=""><a href="../development/services/filter.html">CP/Filter Service</a></li><li  class=""><a >Format Service</a><ul><li  class=""><a href="../development/services/format.html">Format</a></li><li  class=""><a href="../development/services/format/number.html">Number Formatter</a></li><li  class=""><a href="../development/services/format/text.html">Text Formatter</a></li></ul></li><li  class=""><a href="../development/services/ipaddress.html">IP Address Service</a></li><li  class=""><a href="../development/services/live-preview.html">LivePreview Service</a></li><li  class=""><a href="../development/services/memory.html">Memory Service</a></li><li  class=""><a href="../development/services/modal.html">CP/Modal Service</a></li><li  class=""><a >Model Service</a><ul><li  class=""><a href="../development/services/model.html">Model</a></li><li  class=""><a href="../development/services/model/fetching.html">Fetching Models</a></li><li  class=""><a href="../development/services/model/relationships.html">Relationships</a></li><li  class=""><a href="../development/services/model/collection.html">Collections</a></li><li  class=""><a href="../development/services/model/building-your-own.html">Building your own Models</a></li><li  class=""><a href="../development/services/model/relating-models.html">Relating Models</a></li></ul></li><li  class=""><a href="../development/services/pagination.html">CP/Pagination Service</a></li><li  class=""><a href="../development/services/permission.html">Permission Service</a></li><li  class=""><a href="../development/services/sidebar.html">CP/Sidebar Service</a></li><li  class=""><a href="../development/services/spam.html">Spam Service</a></li><li  class=""><a href="../development/services/table.html">CP/Table Service</a></li><li  class=""><a href="../development/services/url.html">CP/URL Service</a></li><li  class=""><a href="../development/services/validation.html">Validation Service</a></li><li  class=""><a href="../development/services/view.html">View Service</a></li></ul></li><li  class=""><a href="../development/tree-datastructure.html">Tree Datastructure</a></li><li  class=""><a href="../development/shared-form-view.html">Shared Form View</a></li><li  class=""><a href="../development/rte-tools.html">RTE Tools API</a></li><li  class=""><a >Control Panel Javascript</a><ul><li  class=""><a href="../development/control-panel-js/events.html">Custom jQuery Events</a></li><li  class=""><a href="../development/control-panel-js/table.html">Table Plugin</a></li><li  class=""><a href="../development/control-panel-js/rich-text-editor.html">Rich Text Editor</a></li><li  class=""><a href="../development/control-panel-js/rangesandselections.html">Ranges and Selections</a></li><li  class=""><a href="../development/control-panel-js/wysihat-api.html">WysiHat API</a></li></ul></li><li  class=""><a href="../development/constants.html">Constants Reference</a></li><li  class=""><a href="../development/json-version-feed.html">JSON Version Feed</a></li><li  class=""><a >Legacy Reference</a><ul><li  class=""><a href="../development/legacy/common-functions.html">Common Functions</a></li><li  class=""><a href="../development/legacy/controllers.html">Controllers</a></li><li  class=""><a href="../development/legacy/drivers.html">Drivers</a></li><li  class=""><a href="../development/legacy/libraries/index.html">Libraries</a><ul><li  class=""><a href="../development/legacy/libraries/creating-libraries.html">Creating Libraries</a></li><li  class=""><a href="../development/legacy/libraries/benchmark.html">Benchmarking Class</a></li><li  class=""><a href="../development/legacy/libraries/cache.html">Cache Class</a></li><li  class=""><a href="../development/legacy/libraries/config.html">Config Class</a></li><li  class=""><a href="../development/legacy/libraries/cp.html">CP Class</a></li><li  class=""><a href="../development/legacy/libraries/database.html">Database Class</a></li><li  class=""><a href="../development/legacy/libraries/email.html">Email Class</a></li><li  class=""><a href="../development/legacy/libraries/file-uploading.html">File Uploading Class</a></li><li  class=""><a href="../development/legacy/libraries/form-validation.html">Form Validation Class</a></li><li  class=""><a href="../development/legacy/libraries/functions.html">Functions Class</a></li><li  class=""><a href="../development/legacy/libraries/image-lib.html">Image Manipulation Class</a></li><li  class=""><a href="../development/legacy/libraries/input.html">Input Class</a></li><li  class=""><a href="../development/legacy/libraries/javascript.html">Javascript Class</a></li><li  class=""><a href="../development/legacy/libraries/language.html">Language Class</a></li><li  class=""><a href="../development/legacy/libraries/layout.html">Layout Class</a></li><li  class=""><a href="../development/legacy/libraries/loader.html">Loader Class</a></li><li  class=""><a href="../development/legacy/libraries/localization.html">Localize Class</a></li><li  class=""><a href="../development/legacy/libraries/logger.html">Logger Class</a></li><li  class=""><a href="../development/legacy/libraries/mime-type.html">Mime Type Class</a></li><li  class=""><a href="../development/legacy/libraries/output.html">Output Class</a></li><li  class=""><a href="../development/legacy/libraries/pagination.html">Pagination Class</a></li><li  class=""><a href="../development/legacy/libraries/rss-parser.html">RSS Parser Class</a></li><li  class=""><a href="../development/legacy/libraries/security.html">Security Class</a></li><li  class=""><a href="../development/legacy/libraries/session.html">Session Class</a></li><li  class=""><a href="../development/legacy/libraries/table.html">Table Class</a></li><li  class=""><a href="../development/legacy/libraries/template.html">Template Class</a></li><li  class=""><a href="../development/legacy/libraries/typography.html">Typography Class</a></li><li  class=""><a href="../development/legacy/libraries/uri.html">URI Class</a></li><li  class=""><a href="../development/legacy/libraries/xmlparser.html">XML Parser Class</a></li></ul></li><li  class=""><a href="../development/legacy/database/index.html">Database Driver</a><ul><li  class=""><a href="../development/legacy/database/active-record.html">Active Record</a></li><li  class=""><a href="../development/legacy/database/results.html">Query Results</a></li><li  class=""><a href="../development/legacy/database/raw.html">Raw Queries and Metadata</a></li><li  class=""><a href="../development/legacy/database/utilities.html">Database Utility Class</a></li><li  class=""><a href="../development/legacy/database/forge.html">Database Forge Class</a></li><li  class=""><a href="../development/legacy/database/connecting-to-an-external-database.html">Connecting to an External Database</a></li></ul></li><li  class=""><a href="../development/legacy/helpers/index.html">Helpers</a><ul><li  class=""><a href="../development/legacy/helpers/array-helper.html">Array Helper</a></li><li  class=""><a href="../development/legacy/helpers/cookie-helper.html">Cookie Helper</a></li><li  class=""><a href="../development/legacy/helpers/directory-helper.html">Directory Helper</a></li><li  class=""><a href="../development/legacy/helpers/download-helper.html">Download Helper</a></li><li  class=""><a href="../development/legacy/helpers/file-helper.html">File Helper</a></li><li  class=""><a href="../development/legacy/helpers/form-helper.html">Form Helper</a></li><li  class=""><a href="../development/legacy/helpers/html-helper.html">HTML Helper</a></li><li  class=""><a href="../development/legacy/helpers/language-helper.html">Language Helper</a></li><li  class=""><a href="../development/legacy/helpers/number-helper.html">Number Helper</a></li><li  class=""><a href="../development/legacy/helpers/path-helper.html">Path Helper</a></li><li  class=""><a href="../development/legacy/helpers/security-helper.html">Security Helper</a></li><li  class=""><a href="../development/legacy/helpers/string-helper.html">String Helper</a></li><li  class=""><a href="../development/legacy/helpers/text-helper.html">Text Helper</a></li><li  class=""><a href="../development/legacy/helpers/url-helper.html">URL Helper</a></li><li  class=""><a href="../development/legacy/helpers/xml-helper.html">XML Helper</a></li></ul></li><li  class=""><a href="../development/legacy/api/index.html">Legacy API Library</a><ul><li  class=""><a href="../development/legacy/api/api-channel-categories.html">Channel Categories API</a></li><li  class=""><a href="../development/legacy/api/api-channel-fields.html">Channel Fields API</a></li><li  class=""><a href="../development/legacy/api/api-channel-structure.html">Channel Structure API</a></li><li  class=""><a href="../development/legacy/api/api-template-structure.html">Template Structure API</a></li></ul></li></ul></li><li  class=""><a >Guidelines</a><ul><li  class=""><a href="../development/guidelines/index.html">Overview</a></li><li  class=""><a href="../development/guidelines/checklist.html">Guidelines Checklist</a></li><li  class=""><a href="../development/guidelines/general.html">General Style and Syntax</a></li><li  class=""><a href="../development/guidelines/in-app-documentation.html">In-app Documentation</a></li><li  class=""><a href="../development/guidelines/performance.html">Performance Guidelines</a></li><li  class=""><a href="../development/guidelines/security.html">Security Guidelines</a></li><li  class=""><a href="../development/guidelines/view-php-syntax.html">View Files and PHP Syntax</a></li></ul></li><li  class=""><a href="../development/v4-addon-migration.html">v4 Add-on Migration</a></li><li  class=""><a href="../development/v3-add-on-migration.html">v3 Add-on Migration</a></li></ul></li><li  class=""><a href="../bugs-and-security-reports.html">Bugs and Security Reports</a></li><li  class=""><a href="../style-guide.html">Docs Style Guide</a></li></ul>
				</div>
			</div>
		</div>

		<section class="docs-content-wrapper">
			<div class="content" id="docsearch-content">
				<!--
    This source file is part of the open source project
    ExpressionEngine User Guide (https://github.com/ExpressionEngine/ExpressionEngine-User-Guide)

    @link      https://expressionengine.com/
    @copyright Copyright (c) 2003-2020, Packet Tide, LLC (https://www.packettide.com)
    @license   https://expressionengine.com/license Licensed under Apache License, Version 2.0
-->


		<h1>
		<span class="anchor" id="date-variable-formatting"></span>
		<a href="#date-variable-formatting">Date Variable Formatting</a>
		</h1><div class="table-of-contents"><ul>
<li><a href="#formatting-dates">Formatting Dates</a></li>
<li><a href="#date-formatting-codes">Date Formatting Codes</a></li>
<li><a href="#relative-dates">Relative Dates</a></li>
</ul>
</div><p>Many tags, including channel fields of the “date” type, are designed to display dates and times. The output of these tags can be formatted so that the date and time appear in the manner you wish. This includes the format of the date, a fixed timezone, and relative date options.</p>
		<h2>
		<span class="anchor" id="formatting-dates"></span>
		<a href="#formatting-dates">Formatting Dates</a>
		</h2><p>The <code>format=</code> parameter enables you to format a date using the date formatting codes listed below. Each code letter is always preceded by a percent sign. For example:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">current_time</span> <span class="hljs-attr">format</span>=<span class="hljs-string">"%F %d %Y"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">January 15 2006</span></code></pre><p>You are allowed to use any character you want within the format parameter, <strong>except</strong> a percent sign. For example, this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">current_time</span> <span class="hljs-attr">format</span>=<span class="hljs-string">"%D, %F %d, %Y - %g:%i:%s"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">Mon, January 15, 2006 - 10:23:45</span></code></pre>
		<h3>
		<span class="anchor" id="setting-the-timezone"></span>
		<a href="#setting-the-timezone">Setting the Timezone</a>
		</h3><p>The <code>timezone=</code> parameter will convert a date to the specified timezone:</p><pre><code><span class="xml">timezone="America/Los_Angeles"</span></code></pre><p>This will override the timezone specified in the <a href="../control-panel/settings/general.html">localization settings</a> in the control panel, and the member’s localization settings. PHP.net has a <a href="http://php.net/manual/en/timezones.php">list of supported timezones</a>.</p>
		<h2>
		<span class="anchor" id="date-formatting-codes"></span>
		<a href="#date-formatting-codes">Date Formatting Codes</a>
		</h2><p>These are all the available formating codes. If you are familiar with PHP, then these will look <a href="http://php.net/manual/en/function.date.php#refsect1-function.date-parameters">remarkably similar</a>:</p><div class="table-wrapper"><table><thead><tr>
<th>Variable</th>
<th>Description</th>
<th>Sample Rendering</th>
</tr>
</thead><tbody><tr>
<td><strong>Seconds</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>%s</td>
<td>seconds</td>
<td>“00” to “59”</td>
</tr>
<tr>
<td>%U</td>
<td>seconds since the epoch</td>
<td></td>
</tr>
<tr>
<td>%u</td>
<td>Microseconds (always 000000, see note, below)</td>
<td>“000000”</td>
</tr>
<tr>
<td><strong>Minutes</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>%i</td>
<td>minutes</td>
<td>“00” - “59”</td>
</tr>
<tr>
<td><strong>Hours</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>%g</td>
<td>hour, 12-hour format without leading zeros</td>
<td>“1” to “12”</td>
</tr>
<tr>
<td>%G</td>
<td>hour, 24-hour format without leading zeros</td>
<td>“0” to “23”</td>
</tr>
<tr>
<td>%h</td>
<td>hour, 12-hour format</td>
<td>“01” to “12”</td>
</tr>
<tr>
<td>%H</td>
<td>hour, 24-hour format</td>
<td>“00” to “23”</td>
</tr>
<tr>
<td><strong>AM / PM</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>%a</td>
<td></td>
<td>“am” / “pm”</td>
</tr>
<tr>
<td>%A</td>
<td></td>
<td>“AM” / “PM”</td>
</tr>
<tr>
<td><strong>Day</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>%d</td>
<td>day of the month, 2 digits with leading zeros</td>
<td>“01” to “31”</td>
</tr>
<tr>
<td>%D</td>
<td>day of the week, textual, 3 letters</td>
<td>“Fri”</td>
</tr>
<tr>
<td>%j</td>
<td>day of the month without leading zeros</td>
<td>“1” to “31”</td>
</tr>
<tr>
<td>%l</td>
<td>(lowercase ‘L’) - day of the week, textual, long</td>
<td>“Friday”</td>
</tr>
<tr>
<td>%w</td>
<td>day of the week, numeric</td>
<td>“0” (Sunday) to “6” (Saturday)</td>
</tr>
<tr>
<td>%N</td>
<td>ISO-8601 numeric representation of the day of the week, numeric</td>
<td>“1” (Monday) to “7” (Sunday)</td>
</tr>
<tr>
<td><strong>Week</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>%W</td>
<td>ISO-8601 week number of year, weeks starting on Monday</td>
<td>“42”: the 42nd week in the year</td>
</tr>
<tr>
<td><strong>Month</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>%m</td>
<td>month</td>
<td>“01” to “12”</td>
</tr>
<tr>
<td>%M</td>
<td>month, textual, 3 letters</td>
<td>“Jan”</td>
</tr>
<tr>
<td>%F</td>
<td>month, textual, long</td>
<td>“January”</td>
</tr>
<tr>
<td>%n</td>
<td>month without leading zeros</td>
<td>“1” to “12”</td>
</tr>
<tr>
<td>%t</td>
<td>number of days in the given month</td>
<td>“28” to “31”</td>
</tr>
<tr>
<td><strong>Year</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>%L</td>
<td>boolean for whether it is a leap year</td>
<td>“0” or “1”</td>
</tr>
<tr>
<td>%o</td>
<td>ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.</td>
<td>“1999” or “2003”</td>
</tr>
<tr>
<td>%y</td>
<td>year, 2 digits</td>
<td>“99”</td>
</tr>
<tr>
<td>%Y</td>
<td>year, 4 digits</td>
<td>“1999”</td>
</tr>
<tr>
<td>%z</td>
<td>day of the year</td>
<td>“0” to “365”</td>
</tr>
<tr>
<td><strong>Other</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>%B</td>
<td>Swatch Internet time</td>
<td></td>
</tr>
<tr>
<td>%e</td>
<td>Timezone identifier</td>
<td>UTC, GMT, Atlantic/Azores</td>
</tr>
<tr>
<td>%I</td>
<td>(capital i)</td>
<td>“1” if Daylight Saving Time, “0” otherwise</td>
</tr>
<tr>
<td>%O</td>
<td>Difference to Greenwich time (GMT) in hours</td>
<td>“-0500”</td>
</tr>
<tr>
<td>%P</td>
<td>Difference to Greenwich time (GMT) with colon between hours and minutes</td>
<td>“-05:00”</td>
</tr>
<tr>
<td>%c</td>
<td>ISO 8601 date</td>
<td>2004-02-12T15:19:21+00:00</td>
</tr>
<tr>
<td>%r</td>
<td>RFC 2822 formatting</td>
<td>“Thu, 21 Dec 2000 16:01:07 +0200”</td>
</tr>
<tr>
<td>%S</td>
<td>English ordinal suffix, 2 characters</td>
<td>“th”, “nd”</td>
</tr>
<tr>
<td>%T</td>
<td>Time zone setting of this machine</td>
<td>MDT</td>
</tr>
<tr>
<td>%Z</td>
<td>time zone offset in seconds. The offset for time zones west of UTC is always negative, and for those east of UTC is always positive.</td>
<td>“-43200” to “43200”</td>
</tr>
</tbody></table></div><p class="alert alert--warn"> <strong>Note:</strong> Dates in ExpressionEngine are most often stored as integers, which translate to whole seconds. So as with PHP’s own <code>date()</code> function, <em>u</em> isn’t a particularly useful formatting code in this context, and will always output <em>000000</em> for microseconds.</p>
		<h3>
		<span class="anchor" id="date-formatting-constants"></span>
		<a href="#date-formatting-constants">Date Formatting Constants</a>
		</h3><p>You may also use the pre-defined Date Formatting Constants listed below for easy access to some standard format strings. For example, this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">current_time</span> <span class="hljs-attr">format</span>=<span class="hljs-string">"{DATE_ATOM}"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">2006-01-15T20:23:45-06:00</span></code></pre><p>Available pre-defined formatting strings are described in the table below.</p><div class="table-wrapper"><table><thead><tr>
<th>Constant</th>
<th>Equivalent</th>
<th>Sample Rendering</th>
</tr>
</thead><tbody><tr>
<td><code>{DATE_ATOM}</code></td>
<td><code>%Y-%m-%dT%H:%i:%s%Q</code></td>
<td>2006-10-16T08:19:39-06:00</td>
</tr>
<tr>
<td><code>{DATE_COOKIE}</code></td>
<td><code>%l, %d-%M-%y %H:%i:%s UTC</code></td>
<td>Monday, 16-Oct-06 08:19:39 UTC</td>
</tr>
<tr>
<td><code>{DATE_ISO8601}</code></td>
<td><code>%Y-%m-%dT%H:%i:%s%Q</code></td>
<td>2006-10-16T08:19:39-05:00</td>
</tr>
<tr>
<td><code>{DATE_RFC822}</code></td>
<td><code>%D, %d %M %y %H:%i:%s %O</code></td>
<td>Mon, 16 Oct 06 08:19:39 -0500</td>
</tr>
<tr>
<td><code>{DATE_RFC850}</code></td>
<td><code>%l, %d-%M-%y %H:%i:%s UTC</code></td>
<td>Monday, 16-Oct-06 08:10:19 UTC</td>
</tr>
<tr>
<td><code>{DATE_RFC1036}</code></td>
<td><code>%D, %d %M %y %H:%i:%s %O</code></td>
<td>Mon, 16 Oct 06 08:19:39 -0500</td>
</tr>
<tr>
<td><code>{DATE_RFC1123}</code></td>
<td><code>%D, %d %M %Y %H:%i:%s %O</code></td>
<td>Mon, 16 Oct 2006 08:19:39 -0500</td>
</tr>
<tr>
<td><code>{DATE_RFC2822}</code></td>
<td><code>%D, %d %M %Y %H:%i:%s %O</code></td>
<td>Mon, 16 Oct 2006 08:19:39 -0500</td>
</tr>
<tr>
<td><code>{DATE_RSS}</code></td>
<td><code>%D, %d %M %Y %H:%i:%s %O</code></td>
<td>Mon, 16 Oct 2006 08:19:39 -0500</td>
</tr>
<tr>
<td><code>{DATE_W3C}</code></td>
<td><code>%Y-%m-%dT%H:%i:%s%Q</code></td>
<td>2006-10-16T08:19:39-06:00</td>
</tr>
</tbody></table></div>
		<h2>
		<span class="anchor" id="relative-dates"></span>
		<a href="#relative-dates">Relative Dates</a>
		</h2><p>Relative dates are always a string indicating the difference between the date and right now. By default the number of years, months, weeks, days, hours, minutes, and seconds are calculated, and the first non zero unit is displayed. Control over which units are calculated, how many units are used in the display, and determining when to stop showing a relative date are available.</p><p>Any date can be displayed with relative language. For example, assuming a channel entry was posted 2 days ago, this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">2 days ago</span></code></pre><p>This also works into the future. For example, assume you have a launch date just 2 days away, this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">launch_date:relative</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">in 2 days</span></code></pre>
		<h3>
		<span class="anchor" id="rounding"></span>
		<a href="#rounding">Rounding</a>
		</h3><p>Relative dates will be rounded to the least significant displayed unit. This only happens when fewer significant units are displayed than were calculated. We do this by examining the number of remaining seconds after we calculate least significant displayed unit. If the remainder equals or exceeds the threshold we round up. The thresholds are outlined in the table below.</p><p><strong>Relative Date Thresholds:</strong></p><div class="table-wrapper"><table><thead><tr>
<th>Unit Rounding To</th>
<th>Remainder Threshold</th>
</tr>
</thead><tbody><tr>
<td>Years</td>
<td>345 days</td>
</tr>
<tr>
<td>Months</td>
<td>25 days</td>
</tr>
<tr>
<td>Weeks</td>
<td>6 days</td>
</tr>
<tr>
<td>Days</td>
<td>22 hours</td>
</tr>
<tr>
<td>Hours</td>
<td>45 minutes</td>
</tr>
<tr>
<td>Minutes</td>
<td>45 seconds</td>
</tr>
</tbody></table></div>
		<h3>
		<span class="anchor" id="parameters"></span>
		<a href="#parameters">Parameters</a>
		</h3>
		<h4>
		<span class="anchor" id="about"></span>
		<a href="#about">about=</a>
		</h4><p>The <code>about=</code> parameter determines what text to use when the date has been rounded. The default is “about”. For example, assuming a date 1 hour and 50 minutes ago this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span> <span class="hljs-attr">about</span>=<span class="hljs-string">"nearly"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">nearly 2 hours ago</span></code></pre>
		<h4>
		<span class="anchor" id="depth"></span>
		<a href="#depth">depth=</a>
		</h4><p>The <code>depth=</code> parameter determines how many calculated units to display, starting from the largest non zero unit to the smallest. The default is “1”. When depth is 2 we will join the two units with “and”. For example, assuming a relative date 4 days, 3 hours, 2 minutes, and 1 second in the past this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span> <span class="hljs-attr">depth</span>=<span class="hljs-string">"2"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">4 days and 3 hours ago</span></code></pre><p>When the depth is greater than 2 the units are displayed with commas. Using the same date as above this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span> <span class="hljs-attr">depth</span>=<span class="hljs-string">"3"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">4 days, 3 hours, and 2 minutes ago</span></code></pre>
		<h4>
		<span class="anchor" id="future"></span>
		<a href="#future">future=</a>
		</h4><p>The <code>future=</code> parameter determines what text is wrapped around the relative date when the date is in the future. Any text is allowed, and all copies of <code>%s</code> will be replaced with the relative date. The default is “in %s”. For example, assuming a date 2 days into the future, this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span> <span class="hljs-attr">future</span>=<span class="hljs-string">"%s until"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">2 days until</span></code></pre><p>Another example:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span> <span class="hljs-attr">future</span>=<span class="hljs-string">"in %s time"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">in 2 days time</span></code></pre>
		<h4>
		<span class="anchor" id="less_than"></span>
		<a href="#less_than">less_than=</a>
		</h4><p>The <code>less_than=</code> parameter determines what text to use when the relative date is below the threshold of the smallest unit. The default is “less than”. For example, assuming a date only seconds old this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span> <span class="hljs-attr">units</span>=<span class="hljs-string">"minutes"</span> <span class="hljs-attr">less_than</span>=<span class="hljs-string">"not quite"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">not quite one minute ago</span></code></pre>
		<h4>
		<span class="anchor" id="past"></span>
		<a href="#past">past=</a>
		</h4><p>The <code>past=</code> parameter determines what text is wrapped around the relative date when the date is in the past. Any text is allowed, and all copies of <code>%s</code> will be replaced with the relative date. The default is “ago”. For example, assuming a date 2 days ago, this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span> <span class="hljs-attr">past</span>=<span class="hljs-string">"%s in the past"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">2 days in the past</span></code></pre>
		<h4>
		<span class="anchor" id="singular"></span>
		<a href="#singular">singular=</a>
		</h4><p>The <code>singular=</code> parameter determines what text to display when the value of a given unit is 1. The default is “one”. For example, assuming a date 1 day in the past this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span> <span class="hljs-attr">singular</span>=<span class="hljs-string">"1"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">1 day ago</span></code></pre>
		<h4>
		<span class="anchor" id="stop"></span>
		<a href="#stop">stop=</a>
		</h4><p>The <code>stop=</code> parameter determines when to stop calculating a relative date and instead display a standard date. When this happens the <a href="#formatting-dates">format=</a> and <a href="#setting-the-timezone">timezone=</a> parameters will be processed. Any valid date/time string parameter for PHP’s <a href="http://www.php.net/manual/en/function.strtotime.php">strtotime()</a> function is acceptable. ExpressionEngine will compute a timestamp based on the date and the provided <code>stop=</code> value. When the current timestamp is greater than or equal to the computed timestamp the date will be displayed as a standard date.</p><p>For example, if you want relative dates but only for one day:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span> <span class="hljs-attr">stop</span>=<span class="hljs-string">"+1 day"</span> <span class="hljs-attr">format</span>=<span class="hljs-string">"%F %d %Y"</span>}</span><span class="xml"></span></code></pre><p>Or perhaps you would rather show relative dates until midnight:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span> <span class="hljs-attr">stop</span>=<span class="hljs-string">"tomorrow"</span> <span class="hljs-attr">format</span>=<span class="hljs-string">"%F %d %Y"</span> <span class="hljs-attr">timezone</span>=<span class="hljs-string">"Pacific/Tahiti"</span>}</span><span class="xml"></span></code></pre><p>If an invalid value is used for <code>stop=</code> a relative date will be displayed.</p>
		<h4>
		<span class="anchor" id="units"></span>
		<a href="#units">units=</a>
		</h4><p>The <code>units=</code> parameter determines which parts of a relative date are calculated prior to displaying them. The following units are available:</p><ul>
<li><code>years</code></li>
<li><code>months</code></li>
<li><code>weeks</code></li>
<li><code>days</code></li>
<li><code>hours</code></li>
<li><code>minutes</code></li>
<li><code>seconds</code></li>
</ul>
<p>When a unit is omitted the next smallest unit will reflect it. For example, assuming a date 8 days old this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span> <span class="hljs-attr">units</span>=<span class="hljs-string">"weeks|days"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">one week ago</span></code></pre><p>But this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">entry_date:relative</span> <span class="hljs-attr">units</span>=<span class="hljs-string">"days"</span>}</span><span class="xml"></span></code></pre><p>Would be rendered like this:</p><pre><code><span class="xml">8 days ago</span></code></pre><p>The default is equivalent to:</p><pre><code><span class="xml">units="years|months|weeks|days|hours|minutes|seconds"</span></code></pre>

				<hr>

				<p class="docs-footer">
					<span>ExpressionEngine 5.4.2 Docs
					<br>
					<span class="copyright"><a href="https://packettide.com/">©2002–2021 Packet Tide,LLC.</a></span>
					</span>
					<a target="_blank" class="docs-contribute-to-page-button" href="https://github.com/ExpressionEngine/ExpressionEngine-User-Guide/blob/stability/docs/templates/date-variable-formatting.md">Edit this page</a>
				</p>
			</div>
		</section>

		<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
		<script type="text/javascript">
			docsearch({
				apiKey: 'ba20cc61ab2d8a0148041c98eeddd9c6',
				indexName: 'expressionengine',
				inputSelector: '#docsearch-input',
				algoliaOptions: { 'facetFilters': ["version:v5"] },
				debug: false
			});
		</script>

		<script src="../_assets/main.min.js"></script>
	</body>
</html>



