This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I mean in a complete format including hours, minute, etc. Like this syntax: YYYY-MM-DDThh:mm:ssTZD.
Hoping you have published_at
defined as a timestamp it will be an instance of Carbon
thus you can simply do
{{ post.published_at.toIso8601String() }}
See Carbon's docs for other common formats. If you don't have it defined as timestamp, I highly recommend you do so because Carbon is just very awesome to use. Read the docs and you'll find out why.
If you cannot define it as a timestamp, then you can do
{{ post.published_at|date('Y-m-d\TH:i:sO') }}
which, by the way, is taken from the PHP DateTime
class documentation. It is even defined as a constant DateTime::ISO8601
but I don't know if or how that can be access through Twig.
Edit: matter of fact found a solution to my last statement:
{{ post. published_at|date(constant('DateTime::ISO8601')) }}
There's also other ways to doing so, just check this SO post or the Twig Docs
It's still always surprising to me what a little Google'ing can reveal.
Last updated
Awesome! I thought it was just specific to October, hehe. But using your second and third solution, it outputs (in May 23, 2016) all dates something like this "2016-05-23UTC00:00:00+0000". The hour, minute, and second is just 00:00:00+0000, while it should be different. Any solution to this?
Is the hour, minute, and second available in the database column? If not then it's clear why, if it is inside the database, then the output might not be found because the |date
filter cannot parse the original value properly (for which you might want to consider using the protected $dates = []
array to define published_at
as date and have it converted to an instance of Carbon
.
1-6 of 6