23 votes

How to show events for "This Weekend, Next Week"

Twigs date_modify filter accepts every string, which is supported by phps strtotime(). These strings are called Relative Formats. . Examples: In the original post you used: {% set day = date('m/d/...
user avatar
  • 8,316
21 votes
Accepted

Display entry post date

{{ entry.postDate | date("M d, Y") }} Inside the date filter, you use the date formatting values documented in the PHP date() documentation. Also, see Craft's DateTime documentation, and the Twig ...
user avatar
  • 7,238
20 votes
Accepted

Get an entry's last modified date

You're looking for the dateUpdated property. {{ entry.dateUpdated }}
user avatar
16 votes
Accepted

How can I output a timeframe in fully written notation nicely?

Add the following macro to your template or import it with a separate twig file. The script allows the start and end date to be the same and outputs a single date instead of a timeframe. Example: ...
user avatar
  • 35.8k
15 votes
Accepted

Advanced query/filter based on date and values

You're actually closer than you might think. All you need to do is add your field handles as parameters. I prefer to use the hash style of declaring parameters but either way will work, I just find ...
user avatar
  • 2,301
13 votes
Accepted

Order entries by date field

Read the article about ElementCriteriaModel in the official Craft docs on how to query elements in general and the craft.entries article about the parameter available to modify the object returned. ...
user avatar
  • 35.8k
13 votes
Accepted

How do I get rid of whitespace when rendering without touching template indentations?

The spaceless tag only removes whitespace between HTML tags. You have to use the whitespace control modifier on your tags to remove leading and or trailing whitespace. Additionally I'd use the ...
user avatar
  • 35.8k
13 votes
Accepted

How do I set up event listing & detail pages with entry post dates that are in the future?

STEP ONE: Create an "Events" section in Craft and uncheck "Entries in this section have their own URLS". STEP TWO: Create your listing page and use ".status('pending')" to have CRAFT return only ...
user avatar
  • 2,455
13 votes
Accepted

Get Age from Date of Birth

Craft's Date/Time field extends PHP's DateTime class so (since 5.3.0) you can use the Diff method like so: yourDateTimeField.diff(now).format('%y')
user avatar
11 votes

How do I get the next year?

You can also get it with: {% set nextYear = now.year + 1 %}
user avatar
11 votes
Accepted

Display entries if Field Date is past Now

You can combine a for and if statement in twig, so you don't necessarily need to use search. Something like this might get you a bit closer: {% for entry in craft.entries.section('event') if entry....
user avatar
9 votes
Accepted

How do I get the next year?

{% set nextYear = now|date_modify('+1 year')|date('Y') %}
user avatar
  • 35.8k
9 votes

How do I set up event listing & detail pages with entry post dates that are in the future?

A better/easier route would be to just create custom Date/Time fields that store the event start and end dates. Entries’ Post and Expiry dates are meant to define when the entry should be visible on ...
user avatar
9 votes
Accepted

First and Last day of Week + Month in Twig

That code in Twig would be: {% set day = now|date('w') %} {% set weekStart = now|date_modify("-#{day} days")|date('m-d-Y') %} {% set weekEnd = now|date_modify("+#{6-day} days")|date('m-d-Y') %}
user avatar
9 votes
Accepted

Creating an archive page with full year and month list

{% set groupedEntries = entriesInYear | group("postDate|date('F')") %} Will give you an associative array where the keys are the months, and the values are the entries for that month. Now you need ...
user avatar
8 votes

How to order by matrix field?

My SuperSort plugin is built for use cases exactly such as this. It allows you to render each object in your array using a Twig object template and sort the array based on the rendered value.
user avatar
  • 3,400
8 votes
Accepted

How do you format a date for saving with users/saveUser on the front end?

Craft stores dates in the database in the following format: Y-m-d H:i:s So submitting the date in this format should work, for example: 2014-06-24 23:30:00 It should also be possible to split the ...
user avatar
  • 6,226
8 votes
Accepted

Empty date field becomes today's date

That happens because the date filter returns the current date for null values / empty strings. If the value passed to the date filter is null, it will return the current date by default. To work ...
user avatar
  • 35.8k
8 votes
Accepted

How to calculate the number of days left?

You want to use "a" as your DateInterval format parameter instead of "d". Also, you may need to use Twig's date function on the end date, which "converts an argument to a date to allow date ...
user avatar
  • 601
7 votes

Showing the month on an archive page

Figured out a way to do this if anyone who has the same problem. {% if year is defined and month is defined %} {% set archiveDate = year ~ '-' ~ month ~ '-01' %} <h2 class='archive-...
user avatar
6 votes

How Do I show advanced Date filters for Events?

Thanks to Brandon Kelly's help I now have Events being filtered by my custom date field called eventDate by doing the following: {% set day = date(craft.request.getSegment(2)) %} {% set nextDay = day|...
user avatar
6 votes

Get an entry's last modified date

Take a look at the EntryModel. The model has a dateUpdated property which will exactly output what you want: {{ entry.dateUpdated }}
user avatar
  • 8,316
6 votes
Accepted

How do I make display a specific post based on what the day of the week it is?

To get the current date and time in Twig use the string "now" and filter it with the date() filter to return it in the format you need (see the list for supported parameters). Then do the if / elseif ...
user avatar
  • 23.6k
6 votes
Accepted

Adjust all date/times to users current timezone

I wouldn’t recommend hacking the MySQL timezone, since that would happen on a global basis, not just for the current user, and will result in some weird race conditions whenever two people are using ...
user avatar
6 votes
Accepted

Change start of the week in Date Picker

Currently this isn’t configurable, but I suppose it should be. I’ll add it to the list, and update this answer when it’s possible. Update: As of Craft 2.3, each user can choose their own preferred ...
user avatar
6 votes
Accepted

How do I save a Plugin's date settings-field?

Yup, you need to use AttributeType::Mixed as Justin Kimbrell suggests. The date will then be escaped and stored in the database like this: * {"newregistrationdate":{"date":"2\/1\/2015"}} Now, the ...
user avatar
6 votes
Accepted

How can I group entries based on a dateTime field?

You're currently grouping on the myDate field, which essentially creates a new array index for each date (e.g. 2016-01-01) which is why you're getting your current output. To group by year, this ...
user avatar
6 votes
Accepted

Date/Time field outputting time with additional minutes

You are using the wrong variables. The 10 is there because it means October not 10 minutes. You have to use | date("g:ia”).
user avatar
  • 3,664
5 votes
Accepted

Order entries by "recently modified" date time in control panel

Short answer is, you can't. Long answer... Ian has some good advice, but the Post Date won't update automatically. Your best solution would be to update the Post Date every time you update something ...
user avatar
  • 23.6k
5 votes
Accepted

How to order by matrix field?

Your example is referencing a field that Twig doesn't know about yet. Also, you usually place the fields you are ordering entries with in quotes (ex: order('dateField')). Matrix blocks are elements (...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible