22

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/Y') %} {% set nextDay = day|date_modify('+1 day') %} but with Relative Formats you can also do something like this: {% set var = day|date_modify('now') %} {% ...


20

{{ 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 date() filter documentation for more information on the topic.


18

You're looking for the dateUpdated property. {{ entry.dateUpdated }}


16

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: 2014-06-13 to 2014-06-13 yields 13 June 2014 The macro: {% macro timeframe(dateStart, dateEnd) %} {# Output day of the start date if necessary #} {{ ...


14

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 this easier to read. {% set params = { section : 'events', order : 'eventDate asc', eventDate : '>=' ~ now, eventType : 'green', limit : '10' } %} {...


13

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. Example code for your events list: {# Get events from `events` section in desired sort order #} {% set allEvents = craft.entries.section('events').order('...


13

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 ternary operator for your conditionals (and put the hyphen inside it): {% for date in entry.d_date %} {{ date.showMonth == 1 ? date.date.month ~ '-' : '' -}} ...


13

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')


12

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 future dated entries. Also use ".order('postDate')" to have Craft order entries so that the next future dated entry is the first in the list: {% set entries = ...


11

You can also get it with: {% set nextYear = now.year + 1 %}


11

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.postDate < now %} {# output your event here #} {% endfor %} It'll just output what meets the criteria if your if statement. The bonus is it doesn't mess ...


9

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 the front end; they are not meant to be part of the entry’s content.


9

{% 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 to loop over all the months, not just the ones in the groupedEntries. Make an array of all the months. {% set allTheMonths = ['January', 'February', 'March', .....


8

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.


8

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 date and time into individual fields as follows: <input type="text" name="fields[customFieldName][date]" value="2014-06-24" /> <input type="text" name=...


8

{% set nextYear = now|date_modify('+1 year')|date('Y') %}


8

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 around this, you would add a conditional. {% if entry.myDate %} Date: {{ entry.myDate|date('Y-m-d') }} {% endif %} Another way to do this is to use a ...


8

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') %}


7

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-title'>Archive for {{ archiveDate|date('F') }} - {{ year }}</h2> {% endif %}


7

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 comparison". This should give you the correct number of days between now and the future date: {{ date( inschrijven.datumEvenement|date ).diff( now ).format('%a') }} ...


6

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|date_modify('+1 day') %} {% set events = craft.entries.eventDate('and, >= '~day|date('Y-m-d')~', <'~nextDay|date('Y-m-d')) %} I have some links in my ...


6

Take a look at the EntryModel. The model has a dateUpdated property which will exactly output what you want: {{ entry.dateUpdated }}


6

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 conditionals similar to how you'd do it in PHP. Another option would be to use the Craft specific switch tag. {% switch "now" | date("l") %} {% case "...


6

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 the site/CP at the same time. Getting an entry to go live at a certain time based on their time zone is a fundamentally different thing than the feature ...


6

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 dateField in your settings template will expect a DateTime object for its value – so just passing getSettings() as is will make it choke. You can get around that ...


6

You are using the wrong variables. The 10 is there because it means October not 10 minutes. You have to use | date("g:ia”).


5

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 else in the entry. Then your Post Date will essentially represent your "last changed" date. Bonus answer... If/when you do build your own plugin, you can look ...


5

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 (like so many things in Craft), and thus are unable to be used for ordering entries. THe reason is that the variable in the returned model is not the actual ...


5

In Twig, the date_modify filter returns a DateTime object. Also, date is not just a filter, but also a function. The date function accepts any a DateTime object or a string in a supported format, and returns a DateTime object. Example: {{ date("+2 years") }} This should give you a DateTime object set for 2 years from when it's triggered. Why is localeTime ...


5

There's no build in functionality for this, but you could make a custom plugin that automatically sets the expiration date expiryDate when you first save an entry with a specific entry type. Another option would be to simply filter your entries from your template: {% set entries = craft.entries.type('myEntryType').postDate('>= ' ~ now|date_modify('-10 ...


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