DateTime objects provide information about a given date/time.
Questions tagged [datetime]
217 questions
8
votes
1 answer
Get Age from Date of Birth
I have an entry with a dateOfBirth Date/Time Field.
Is it possible to calculate the current age from that field?
I can't find a craft/twig function/filter to calculate the difference between 2 dates.
mmc501
- 1,779
- 13
- 34
4
votes
1 answer
Should the timezone in general settings effect the output of $time = date("g:ia");?
I am using the following in a plugin which I would expect to simply output the time of the server.
// get current time
$time = date("g:i a");
// outputs 9:36am
In a straight .php file this is correct - however, from within the plugin the time is an…
Taylermade
- 131
- 1
- 5
4
votes
1 answer
How to get entries between a time
I'm using Craft 3 and I would like to do the following thing:
There is a start date and an end date filed in entry, is it possible to get entries that are between these two dates in PHP?
Thank you!
yu xia
- 397
- 2
- 14
3
votes
1 answer
How to query entries and take into account the timezone offset? - ChartHelper
I'm trying to query a range of entries and my results are not returning all the entries in the range I am trying to target. My situation relates to displaying data on a chart using the Craft ChartHelper class, but I'm not sure if this issue is…
Ben Parizek
- 13,448
- 1
- 33
- 98
3
votes
2 answers
date_modify relative time
I'd like to reopen this question:
The answer was a plugin called Nice Time
But This plugin is depricated and the creator stats that this functionality is acheivable via the date_modify filter.
Yes okay, but how?
I have a event archive where I want…
KSPR
- 3,786
- 2
- 29
- 52
2
votes
3 answers
Empty date field becomes today's date
I have a date field, and I want it to be possible for this to be empty. How it works now is that if you don't enter a value, it takes today's date. Any suggestions?
Wobee
- 328
- 2
- 9
2
votes
1 answer
Change Dates in Craft CMS
I want to change the dates of entries before the dates I actually edited the entries, I am trying to look in the database and I can't figure out which dates need to be changed. I have entries in Craft CMS of past dates and was looking for a way to…
user1837279
- 31
- 1
2
votes
1 answer
Check if we're the second or last sunday of the month today
How can I check if today is the second or last sunday of this month?
My effort:
{% set now = now|date('U') %}
{% set monthyear = now|date('F Y') %}
{% set secondSunday = now|date_modify("#{monthyear} second sunday")|date('U') %}
{% set lastSunday =…
mdmngz
- 157
- 6
2
votes
1 answer
Store Hours: show current open/closed state
I'm wanting to do two things with this great plugin, but am having a bit of a mind-melt...
1) I'd like to show the current state; e.g. Closing soon; Open now; Closed; Opening Soon
2) I'd like to show the current day highlight:
Sunday: 11:00 AM -…
Darren Wood
- 117
- 6
2
votes
2 answers
Custom field filtering
Why does this work fine
{% paginate craft.entries().limit(7).section('events').eventStartDate('>= ' ~ 2014 ~ '-' ~ 09) as entriesOnPage %}
But this does not
{% paginate craft.entries().limit(7).section('events').eventStartDate('>= ' ~ 2014 ~ '-' ~…
Matt Green
- 428
- 4
- 6
1
vote
1 answer
Set conditional parameter to not output "dateUpdated" field, when entry is first time created
I was going through my code for testing purposes and found out, that When entry's first time created, it also outputs data from the field "dateUpdated".
I'm assuming, when an entry is first time created it is also first time updated.
So I'm trying…
Dominik Krulak
- 1,562
- 14
- 27
1
vote
1 answer
Use date field to show related posts
I have a route setup for Dates and would like to show all entries from that particular Day and Month.
For example, clicking 29/11/2022 would take you to mysite.com/dates/29-11 and I would like to see all posts with a date field matching…
supazu
- 576
- 4
- 12
1
vote
1 answer
Current day display on day later
in the CP settings, timezone is set to UTC +1 Europe/Zurich
when I try this code:
{% set currDay = now|date() %}
{{ currDay|date('l d F Y') }}
it outputs "Mercredi, 16 janvier 2019", but we're still Tuesday 15th
Craft 3.0.37
jjem
- 497
- 2
- 14
1
vote
0 answers
HTML5 date input field in Chrome ignores twig formatting?
Im sorry, as I was formulating this question I discovered the answer. Chrome only accepts dates in ISO format (the accepted format for Chrome Date field is YYYY-MM-DD). So use:
Eli Peters
- 31
- 2
1
vote
1 answer
Escaping characters in entry.postDate|date
{{ entry.postDate|date('jS F Y \at ga') }}This should produce this 5th November 2016 at 4ambut it doesn't seem to recognise the escape and adds 30 instead of at.
Nutmeg
- 598
- 1
- 4
- 17