Documentation · ViewHelper reference

Format / DateViewHelper


Formats a \DateTime object.

Examples

Defaults

<f:format.date>{dateObject}</f:format.date>

Output

1980-12-13
(depending on the current date)

Custom date format

<f:format.date format="H:i">{dateObject}</f:format.date>

Output

01:23
(depending on the current time)

Relative date with given time

<f:format.date format="Y" base="{dateObject}">-1 year</f:format.date>

Output

2016
(assuming dateObject is in 2017)

strtotime string

<f:format.date format="d.m.Y - H:i:s">+1 week 2 days 4 hours 2 seconds</f:format.date>

Output

13.12.1980 - 21:03:42
(depending on the current time, see http://www.php.net/manual/en/function.strtotime.php)

Localized dates using strftime date format

<f:format.date format="%d. %B %Y">{dateObject}</f:format.date>

Output

13. Dezember 1980
(depending on the current date and defined locale. In the example you see the 1980-12-13 in a german locale)

Inline notation

{f:format.date(date: dateObject)}

Output

1980-12-13
(depending on the value of {dateObject})

Inline notation (2nd variant)

{dateObject -> f:format.date()}

Output

1980-12-13
(depending on the value of {dateObject})

  • Tag usage example

    <f:format.date date="[mixed]" format="''" base="[mixed]">
    	<!-- tag content - may be ignored! -->
    </f:format.date>
  • Inline usage example

    {f:format.date(date: [mixed], format: '''', base: [mixed])}

Arguments

Argument Description Type
base

A base time (a DateTime object or a string) used if $date is a relative date specification. Defaults to current time.

mixed
date

either a DateTime object or a string that is accepted by DateTime constructor

mixed
format

Format String which is taken to format the Date/Time

string
Required attribute

Revision history

commit f5489abd9b2d3c2e4cdd22eaec14a1c240fe4729
Author: Christopher Hlubek <*****@networkteam.com>
Date:   Fri Mar 27 15:14:41 2009 +0000

    Implemented a basic date view helper

commit 3ef7ac06f12356785e7d8887b847fd010a886826
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Tue Mar 31 11:49:37 2009 +0000

    Fluid:
    * Added Form* view helpers backported from v5
    * Adjusted view helpers to refactoring of URIHelper

commit 5ffb78a94b6eedab71ba6a7dfb3ee207e773f830
Author: Niels Pardon <*****@niels-pardon.de>
Date:   Sun Apr 12 11:07:15 2009 +0000

    Added type hinting to render() method of ActionlinkViewHelper, TypolinkViewHelper and DateViewHelper

commit 38ebcedd944471b83d9293b648264fd3e65634f1
Author: Bastian Waidelich <*****@typo3.org>
Date:   Tue May 5 20:52:33 2009 +0000

    Fluid:
    * Changes backported from FLOW3:
      * major cleanup and refactoring of core and view helper classes & comments
      * added validation for boolean arguments in AbstractViewHelper
      * added initialize-method to AbstractViewHelper, that is called before render(). This was especially needed for tagbased viewhelpers.
      * renderChildren() now directly calls evaluateChildNodes() on the respective view helper node allowing us to render objects/arrays.
      * improved boolean type conversion for arguments in ViewHelperNode.
      * added TagBuilder class, re-wrote all tag based view helpers to use it (see form view helpers for some examples)
      * ViewHelperArguments collection got a new method "hasArgument()" that returns TRUE when the specified argument exists and is not NULL
    * tx_fluid changes:
      * Improved fake object factory. Now objects are injected to subclasses and implementations of the specified classes/interfaces.
      * cleaned up and tweaked view helpers. Removed Parsefunc, Stdwrap and TypoScript view helpers for now. Added CObject, If/Then/Else, EmailLink, Crop, Currency, Debug, HTML, Nl2br, Image view helpers. Thanks to Sebastian Böttger, Christopher Hlubek, Niels Pardon, Andreas Pattynama for the help!
    * Note: Unit tests not fully backported yet.

commit 603bd876368b8c96e16e8a4eec8f589dba82631f
Author: Bastian Waidelich <*****@typo3.org>
Date:   Tue May 5 21:13:54 2009 +0000

    Fluid:
    * updated currency, date, number and printf view helpers to use tag contents as their main input as discussed in the mailing lists. This will most probably break your existing fluid templates (again) - but, hey, thats bleeding edge.

commit 1c33c299575f821dafc5b2f246ae2ea99e5ec0d5
Author: Bastian Waidelich <*****@typo3.org>
Date:   Fri May 8 11:07:09 2009 +0000

    Fluid:
     * Improved Backport (prefix "Tx_Fluid..." won't be applied within comments
     * If a view helper throws a ViewHelperException, that will be caught in ViewHelperNode to be able to react differently depending on the execution context (e.g. the error message could be outputted only when the current IP is within "devIPmask"). See DateViewHelper for an example.
     * fixed EmailViewHelper. Since latest changes $this->renderChildren() returns NULL instead of an empty string if tag has no content
     * removed test code from TranslateViewHelper.. sorry
     * Modified ActionlinkViewHelper & TypolinkViewHelper according to the latest URIHelper changes
     * unit tests on their way!

commit 50af6b9c08d04e3e1d4ce56a499a9a3d4b84efc3
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Thu May 28 21:45:46 2009 +0000

    Fluid:
    * Backported major changes from Fluid v5 to Fluid v4
    * !!! Many of these changes are not backwards-compatible! Please read this if you have written custom ViewHelpers!
    * Introduced Shorthand Syntax for calling ViewHelpers
    * Core:
    ** Lots of internal cleanup and refactorings.
    ** !!! Complete restructuring into subpackages.
    * ViewHelpers:
    ** !!! The base classes of ViewHelpers changed to Tx_Fluid_Core_ViewHelper_AbstractViewHelper and Tx_Fluid_Core_ViewHelper_TagBasedViewHelper. Please adjust your ViewHelpers!
    ** !!! $this->variableContainer has been renamed to $this->templateVariableContainer
    ** !!! the view is not in $this->variableContainer anymore. Currently there is no way to fetch the View from a ViewHelper.
    ** Introduced a new $this->controllerContext containing the context variables of the controller
    ** !!! The request can be now found in $this->controllerContext->getRequest()
    ** !!! The URIHelper has been renamed to URIBuilder and can be now found in $this->controllerContext->getURIBuilder()
    ** Introduced a new ViewHelperVariableContainer, available in $this->viewHelperVariableContainer to pass data between ViewHelpers. Should only be needed in very rare cases.
    ** !!! Removed <f:format.htmlEscape> ViewHelper! Please remove these declarations in your template! Escaping of object accessors is now automatically done, see next point.
    * !!! ObjectAccessors {...} are now automatically HTMLspecialChar'd if not used as an argument to a ViewHelper. This is done using a new ObjectAccessorPostProcessor. Lateron, this will be made configurable.

commit 50af2479b72ce04ea9efb888da68873b990a08df
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Mon Aug 3 07:30:07 2009 +0000

    [~TASK] Fluid: R*****@internal annotations and added @api annotations
    [~TASK] Fluid: Now, one ViewHelperNode only ever uses one instance of a ViewHelper

commit 9b2830bc1c17588dd69a463773c5f05f61b5cf94
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Sat Oct 24 11:01:38 2009 +0000

    * A*****@api annotations
    * Changed the fluid-specific RuntimeException to SPL's RuntimeException.

commit 7868047c52417ff4e1f3e99e45adaba1ee3d0a24
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Sat Oct 24 11:49:45 2009 +0000

    [~TASK] Fluid: A*****@package and @subpackage annotations.

commit dc145d3c60e5fedf206f997742b6deba69fde8f9
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Thu Oct 29 07:24:15 2009 +0000

    [!!!][+FEATURE] Fluid: Strings inside Arrays and the inline notation are now parsed by Fluid as well. This enables things like {fullName: '{firstName} {lastName}'} - thus, everything can be nested inside arrays and the ViewHelper inline notation arguments. This is a breaking change in case you used literal {...} inside your arguments, but not else. Relates to #5118.
    [+FEATURE] Fluid (ViewHelpers): extended format.date viewhelper by an additional "date" argument. Now you can write {f:format.date(date: 'yesterday')} in your templates. This change is backwards compatible! Relates to #5150
    [+FEATURE] Fluid (ViewHelpers): extended if viewhelper by arguments "then" and "else". Now you can write {f:if(condition: 1, then: 'yes', else: 'no'} in your templates. This change is backwards compatible! Relates to #5150
    [~TASK] Fluid (Core): added check for reserved keywords to TemplateVariableContainer. This relates to #5158
    [~TASK] Fluid (Tests): moved and renamed VariableContainerTest
    ~TASK] Fluid (Core): Changed method names (handler_*) in TemplateParser, resolves #5135.
    [~TASK] Fluid (Tests): Cleanup to comments and "framework code", resolves #5136.

commit 06372a84a645147029501d2b2b06a4fdfe56b7d7
Author: Michael Stucki <*****@typo3.org>
Date:   Wed Nov 25 21:53:57 2009 +0000

    Add missing SVN properties for new or modified files

commit ed19fe9e4a6d2e91c594784adea24aa82064dd47
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Mon Jul 12 20:18:26 2010 +0000

    Fluid in v5 and v4 are now synchronized again!
    
    [+FEATURE] Fluid: The TemplateVariableContainer now provides a method to retrieve all variables.
    [~TASK] Fluid (Core): Introduced a RenderingContextInterface to more cleanly decouple Fluid's rendering context from the TypoScript rendering context. Note that view helpers (and other code) should now refer to that interface instead of the concrete Fluid implementation!
    [!!!][+BUGFIX] Fluid (Core): Refactored all Condition-ViewHelpers like f:if, f:security.if* to use a newly created base class F3\Fluid\Core\ViewHelper\ConditionViewHelper. This greatly simplifies the implementation of custom conditions. However, THIS IS A BREAKING CHANGE in case you copied the f:if ViewHelper to create a custom condition ViewHelper, as the internal workings changed. Please check the new f:if ViewHelper to see how to adjust your ViewHelper -- you basically just have to throw away a lot of code. Resolves #8824.
    [!!!][-API] Fluid (TemplateView): Removed renderSection() and renderWithLayout() from public API in Tx_Fluid_View_TemplateView, as this should only be called from inside Fluid.
    [!!!][TASK] Fluid (ViewHelpers): the <f:section />-ViewHelper now does NOT render itself anymore when encountered in a normal template. Example: Before the change, the template "before <f:section name='...'> middle </f:section> after" was rendered as "before middle after", but now it is only rendered as "before after". Although this is a breaking change, it is quite unlikely that anybody relied on this behavior, as it was inconsistent beforehand.
    [TASK] Fluid (TemplateView): Major refactoring of the layout, partial and section rendering mechanism. This also induces a speedup as retundant rendering is eliminated.
    [+FEATURE] Fluid (ViewHelpers): The <f:render>-ViewHelper can be now used to render sections in the same partial and template. In these cases, all arguments need to be specified explicitely. Additionally, it can now be used to render a section recursively.
    [~TASK] Fluid (Core): Removed some non-API-methods which were never called.

commit 186bdaeac89820779f91853b830cc95d60c7ad58
Author: Bastian Waidelich <*****@typo3.org>
Date:   Tue Jul 13 09:42:26 2010 +0000

    [-TASK] Fluid: R*****@version annotation from all Fluid classes to ease the backporting process. Relates to #8835 (backported from Fluid package)

commit 1d36de6ed90007e324b773782e8f0a1d1c1191a2
Author: Bastian Waidelich <*****@typo3.org>
Date:   Tue Jul 13 10:12:30 2010 +0000

    [-TASK] Fluid: R*****@package/@subpackage annotations from all Fluid classes. They have already been removed in FLOW3 packages in r2813.

commit 472451987ca0530fa5828bb0b79fcafa2f905a35
Author: Bastian Waidelich <*****@typo3.org>
Date:   Fri Nov 19 20:58:09 2010 +0000

    [-TASK] Fluid: R*****@scope annotations as they are not used in v4

commit dd8928aed4c119d8db37322acb91ded24ba5cc35
Author: Bastian Waidelich <*****@typo3.org>
Date:   Thu Dec 30 16:21:11 2010 +0000

    [+TASK] Fluid (ViewHelpers): Fix, cleanup and extend inline documentation of ViewHelpers
    
    Resolves #10908

commit 84a5cb71a458234830c64256c2ae5e782a0b63f8
Author: Bastian Waidelich <*****@typo3.org>
Date:   Tue Jan 25 13:37:03 2011 +0000

    [+FEATURE] Fluid (ViewHelpers): DateViewHelper now supports strftime format strings
    
    Until now format.date did not support localized format strings as it internally used
    the DateTime format strings.
    Note: DateTime formats are still supported for backwards compatibility reasons,
    but a deprecation log entry will be written and the support will probably be
    dropped with version 1.5.
    Thanks to Steffen Ritter, Marc Bastian Heinrichs and Franz Koch for their patches!
    
    Resolves: #9174

commit 9a43f7a2a3b33171b49662ae50fb2920224c50a9
Author: Bastian Waidelich <*****@typo3.org>
Date:   Tue Jan 25 19:36:15 2011 +0000

    [+TASK] Fluid (ViewHelpers): format.date added inline documentation for localized dates
    
    Thanks to Franz Koch
    
    Relates to: #9174

commit 3348f6643afeab012e321e48578447d773480297
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Wed Jan 26 08:08:16 2011 +0000

    Reverting r3994: DateViewHelper now supports strftime format strings
    
    because of non-consensus in discussion.

commit 0401b77da4a7e019f40f60737724da2d6238f521
Author: Sebastian Kurfuerst <*****@typo3.org>
Date:   Fri May 27 07:19:55 2011 +0200

    [TASK] Comment and non-functional changes
    
    ... appeared during bringing Fluid v4 and v5 in sync again
    
    Change-Id: I326663606a917ad84fa82a736a536ff77863a0b3

commit 42d159e585fa5c56ad440c03d6e4a64af9a20828
Author: Bastian Waidelich <*****@typo3.org>
Date:   Thu Jul 28 13:54:35 2011 +0200

    [BUGFIX] Deactivate EscapeInterceptor for certain ViewHelpers
    
    This change deactivates automatic escaping for ViewHelpers that rely
    on the raw value.
    
    Change-Id: I895a359aad05c6fbac4d476d7d8eb4f07da1acdc
    Related: #27678

commit fd09d197fa8886b97cb20aa9573f39cd08ce989e
Author: Bastian Waidelich <*****@typo3.org>
Date:   Thu Nov 10 18:27:58 2011 +0100

    [TASK] S*****@author annotations
    
    This backports three recent changes of the TYPO3.Fluid package:
    - R*****@license annotation from files (290f4f5)
    - Simplify license header in PHP files (14bacba)
    - D*****@author tags from source code (9c2e837)
    
    This should not contain any functional change!
    
    Change-Id: I9376dca4af78c4f0f82413011d115b8ad04634dd

commit ec3891d8d4e339d8319428211207e6201be9fd73
Author: Thomas Maroschik <*****@dfau.de>
Date:   Wed Oct 17 21:18:26 2012 +0200

    [TASK][WIP] Move non class code back to source files
    
    Change-Id: I620d2e61860142cdc89cc83474c95542799961c0

commit 554e8f890dcc0dd86a27518b58e2b54be26fd37e
Author: Thomas Maroschik <*****@dfau.de>
Date:   Wed Oct 17 22:20:17 2012 +0200

    [TASK] Namespace classes
    
    Change-Id: Ia7432e1c923826ed58206bca15fb94509adbd508

commit 547ef7f60f39c6bfcb0376e5e76070da85860098
Author: Arvid Jakobsson <*****@gmail.com>
Date:   Mon Sep 17 21:25:51 2012 +0200

    [TASK] Remove superfluous parenthesis in sysexts
    
    Superfluous brackets in fluid after namespaces move
    Change ("a" . "b") . "c" into "a" . "b" . "c" using the lex-pass tool.
    
    Resolves: #41016
    Related: #40095
    Releases: 6.0
    Change-Id: I64741473cb24eda343f0576ebd1a0f1846dfc3f8
    Reviewed-on: http://review.typo3.org/14675
    Reviewed-by: Oliver Hader
    Tested-by: Oliver Hader

commit 9d13dedf017b614b834261b1bf5d4acb2201f1d4
Author: Alexander Schnitzler <*****@typovision.de>
Date:   Fri Nov 16 19:49:02 2012 +0100

    [CLEANUP] Replace FLOW3 with TYPO3 Flow
    
    Releases: 6.0
    Fixes: #43036
    Change-Id: I62df23587301b4cde3ddeae3686b34f54fe1182e
    Reviewed-on: http://review.typo3.org/16498
    Reviewed-by: Alexander Schnitzler
    Tested-by: Alexander Schnitzler

commit 9d46e6932d35c79bf87c96fa38b8e537c4192f23
Author: Alexander Schnitzler <*****@typovision.de>
Date:   Tue Nov 20 16:27:02 2012 +0100

    [CLEANUP] Adjust code to CGL and fix small namespace bugs
    
    * whitespaces, tabs and blank line issues
    * bool -> boolean
    * int -> integer
    * fix wrong namespace annotations
    
    Fixes: #43157
    Releases: 6.0
    Change-Id: I8397948e19248db029d8efd1555ee56e4982742d
    Reviewed-on: http://review.typo3.org/16619
    Reviewed-by: Helmut Hummel
    Tested-by: Helmut Hummel

commit b5006c26ffd5f1badaf4d58ea6c849e7907e5b4e
Author: Anja Leichsenring <*****@ab-softlab.de>
Date:   Sun Feb 3 14:11:44 2013 +0100

    [BUGFIX] Date ViewHelper not using configured Timezones
    
    The date viewhelper does not respect the configured timezone.
    
    After the default timezone is set during Bootstrap, it is enough to
    retrieve the setting from environment.
    
    Additional a condition tests the proper format of timestamps and adds
    the '@' if it is missing.
    
    For the formatted output with '%' strftime function is added, too.
    
    Fixes: #12769, #43363, #9174
    Releases: 4.5, 4.6, 4.7, 6.0, 6.1
    Change-Id: I782b4ec00537519768335da9ba32822a42108ea1
    Reviewed-on: https://review.typo3.org/17976
    Reviewed-by: Wouter Wolters
    Tested-by: Wouter Wolters
    Reviewed-by: Jigal van Hemert
    Tested-by: Jigal van Hemert
    Reviewed-by: Anja Leichsenring
    Tested-by: Anja Leichsenring

commit cc51602541b7d12c97f065818f174808c6613eb8
Author: Anja Leichsenring <*****@ab-softlab.de>
Date:   Thu Feb 7 21:15:05 2013 +0100

    [BUGFIX] Remove superfluous newline
    
    With #12769 a superfluous newline was accidentely merged.
    This patch removes it.
    
    Fixes: #45256
    Releases: 6.1
    Change-Id: I05448276cf1793b2986ddf9831a83dc96e19824b
    Reviewed-on: https://review.typo3.org/18094
    Reviewed-by: Anja Leichsenring
    Tested-by: Anja Leichsenring

commit 50d433bbde06b4b9eab146caea64d09239949e64
Author: Tymoteusz Motylewski <*****@gmail.com>
Date:   Sun Mar 3 18:53:42 2013 +0100

    [TASK] Sync CMS Fluid with Flow Fluid 1.1 (part2)
    
    This is the second part of a backport fluid from Flow.
    
    Change-Id: I96e47131414c50801ff7628508dc05d7d7b5e106
    Releases: 6.1
    Resolves: #44819
    Fixes: #45985
    Reviewed-on: https://review.typo3.org/18163
    Reviewed-by: Wouter Wolters
    Tested-by: Wouter Wolters
    Reviewed-by: Marc Bastian Heinrichs
    Tested-by: Marc Bastian Heinrichs

commit 77f29a3c69a7cbb27b34072754aa503bace6c9f1
Author: Christian Kuhn <*****@schwarzbu.ch>
Date:   Tue Oct 1 14:40:56 2013 +0200

    [TASK] Remove closing PHP tags
    
    Change-Id: Iaa92566c53301e49396fc9fb26b0b339c48d567b
    Resolves: #52360
    Releases: 6.2
    Reviewed-on: https://review.typo3.org/24212
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn
    Reviewed-by: Ernesto Baschny
    Tested-by: Ernesto Baschny
    Reviewed-by: Anja Leichsenring
    Tested-by: Anja Leichsenring

commit bb92edbba5a927298eaef7b649cd3dce96e77a85
Author: Felix Kopp <felix-*****@phorax.com>
Date:   Sat Feb 8 14:12:24 2014 +0100

    [!!!][TASK] Set f:format.date format to system default
    
    TYPO3 configuration knows a global date format configuration
    within the installation tool. See TYPO3_CONF_VARS/SYS/ddmmyy.
    
    Use this global format as the default for all fluid based date
    format outputs if not overwritten in place.
    
    Change-Id: I508d7f61f63760aa1301f52663c432feeb539bf4
    Resolves: #55790
    Releases: 6.2
    Reviewed-on: https://review.typo3.org/27456
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn
    Reviewed-by: Marcin Sągol
    Tested-by: Marcin Sągol
    Reviewed-by: Anja Leichsenring
    Tested-by: Anja Leichsenring