Morrigan Posted April 17, 2016 Posted April 17, 2016 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. Thanks! Ali Majrashi, Real Mythotical, Greek76 and 2 others 5
Mark Posted April 17, 2016 Posted April 17, 2016 {datetime="whatever" dateonly="true"} Morrigan, Evgeny Bobokal and rubiksw 3
Morrigan Posted April 17, 2016 Author Posted April 17, 2016 @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.
Colonel_mortis Posted April 17, 2016 Posted April 17, 2016 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. Quote {datetime="$timestamp" dateonly="[boolean]" norelative="[boolean]" lowercase="[boolean]" short="[boolean]"} Shows a time formatted according to the user's locale Parameters$timestamp - A timestamp to transform into a datedateonly - 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) Morrigan 1
marklcfc Posted June 18, 2016 Posted June 18, 2016 Is there a way to correct the date to as it was in 3.4? I don't find Yesterday accurate at all. I'm typing this on the 19th now but the topics with last posts from the 17th show as Yesterday
marklcfc Posted June 28, 2016 Posted June 28, 2016 And like the post above, it just says June 19. I want the show the time too.
Evgeny Bobokal Posted July 14, 2016 Posted July 14, 2016 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
Mark Posted July 14, 2016 Posted July 14, 2016 \IPS\DateTime::ts( $comment->mapped('date') ) Evgeny Bobokal 1
Evgeny Bobokal Posted July 14, 2016 Posted July 14, 2016 Awesome! This worked for me as well: {datetime="$comment->mapped('date')" norelative="true"}
Mac1 Posted December 19, 2020 Posted December 19, 2020 Why datetime function doesn't show "Today at 10:00" but only "19 December"... Past time works good, function is rendering "yesterday" properly.
bfarber Posted December 21, 2020 Posted December 21, 2020 Our relative date formatting does not show relative dates for the future, only for the past.
Dreadknux Posted February 23, 2023 Posted February 23, 2023 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?
Recommended Posts