Jump to content

Date and Time formatting


Recommended Posts

So one thing I found that I need is not exactly possible at the moment. Date and Time formatting in templates.

Right now you are forced into the relative time with the date growing as the age grows I need to be able to format a template to have MM/DD/YYYY and no time but currently I can only have things like "Yesterday" or "23 February". It would be nice to be able to format my dates again.

I think that there are possibly 2 ways to go about this. One would be to create separate template classes for it and allow us to format it in a setting (date, datetime, relative, shortdate etc) or give us the option to format it in the template bit itself like this:

{datetime="$record->record_publish_date" format="m/j/Y"}

Where it will take the date and format it (in this instance) 4/17/2016. Something like this, I think, would likely be the easiest as then the core date formatting isn't changed but still allows for theme makers and people that want custom date formatting in page templates and blocks the opportunity to change them as needed.


Link to comment
Share on other sites

1 hour ago, Morrigan said:

@Mark Are there other options for the datetime method? This will do what I need for now but custom formatting and whatnot would be awesome or at least a list of them.


{datetime="$timestamp" dateonly="[boolean]" norelative="[boolean]" lowercase="[boolean]" short="[boolean]"}
Shows a time formatted according to the user's locale

$timestamp - A timestamp to transform into a date
dateonly - Show only the date (with no time)
norelative - By default, relative times will be used (e.g. 8 hours ago). To always show an absolute date/time, set this to true.
lowercase - By default, date strings will be capitalized where necessary (e.g. Yesterday, 8:32pm). Setting this to true ensures it is lowercase, for use in a sentence.
short - Uses a very short date format (ideal for mobile devices)


Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 3 weeks later...
On 4/17/2016 at 11:48 PM, Mark said:

{datetime="whatever" dateonly="true"}


How to apply this to a $comment object? All fields and methods I tried to guess, it didn't work.

Current template {$comment->dateLine()|raw} will generate:

<time datetime="2016-05-18T16:33:57Z" title="05/18/2016 07:33  PM" data-short="May 18">May 18</time>

But I need only this:

05/18/2016 07:33  PM


Link to comment
Share on other sites

  • 4 years later...
  • 2 years later...

Sorry to revive a dead thread, but I wanted to see if this suggestion was being taken on board? I think having more options for formatting the datetime parameter would be great on the theming level. For example, I might want a datetime on profiles only to read as:

Aug 31, 2022

With short month names. Which I can't do at present with the current boolean options.

Is it possible to add a ' format="m/j/Y" ' parameter to allow for a full suite of date and time options, as Morrigan suggests in the OP?

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...