Questions tagged [datetime]

DateTime objects provide information about a given date/time.

Filter by
Sorted by
Tagged with
17
votes
1answer
1k views

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

Stemming from this original post I was able to show Events using a custom date field and successfully got "Today" and "Tomorrow" events to show up. How would I go about doing some custom Math to show ...
12
votes
3answers
4k views

Get an entry's last modified date

Trying to determine if there is a method for getting an entry's last modified date, preferably date-time. Gave a good look over the docs and some searching and couldn't find anything other than the ...
11
votes
3answers
2k views

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

I'm struggling to set up a listing template and a detail template which will display "event" entries with post date set in the future. I keep getting a 404 error on the detail page. How do I set up ...
11
votes
2answers
1k views

Search matrix for blocks with upcoming dates

I have a matrix field with one "event" block type that contains several fields. One of those fields is a date field. Is there a way to get just blocks with upcoming dates?
10
votes
1answer
221 views

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

Let's say you have two dates and want to output the timeframe in fully written "day month year - day month year" notation, but want to leave out the month and year parts of the start date if ...
10
votes
1answer
6k views

Advanced query/filter based on date and values

I have a channel of events with a field ‘eventDate’ for the date/time of the event. Within that there are ‘types’ of events ‘eventType’. What would be the most efficient way of outputting the NEXT (...
9
votes
2answers
5k views

Display entries if Field Date is past Now

I'm trying to make a upcoming and past event page. I can make an if statement for displaying the past or upcoming events but the problem is if I limit the amount of entries to be displayed I realised ...
9
votes
2answers
12k views

Is it possible to compose a DateTime object from a string?

I experienced that there is a difference between real DateTime objects (as now is one) and strings composed to "fake DateTime objects" (ie. {% set myDate = '2014/06/24' %}). Sometimes it makes no ...
8
votes
2answers
3k views

Multilingual Dates where date format varies

I have a multilingual site, and I want my dates formatted like: English site: July 13, 2014 Italian site: 13 lulgio 2014 So the month name is translated, and the order of the elements changes as ...
8
votes
1answer
2k views

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....
8
votes
1answer
8k views

Order entries by date field

I have a channel section with a handle named 'events'. In my field layout for this section I have a field named eventsDate, which is a Date/Time field. I also have a plain text field called '...
8
votes
3answers
9k views

How to calculate the number of days left?

I want to calculate the remaining days between the current day (now) and a future date set as a date field in {{ inschrijven.datumEvenement }} globals {{ inschrijven.datumEvenement.diff(now).format('%...
7
votes
1answer
436 views

How Do I show advanced Date filters for Events?

I am trying to setup an events section similar to that of Yelp's Events. They have a listing of all the upcoming events and have filters on the side for "Today, Tomorrow" etc... I received help from ...
6
votes
1answer
13k views

Display entry post date

How do I display my entry post date, formated as "May 24, 2015"? I know this is a very basic question, but I can never find these easy answers in either the Craft or Twig documentation.
6
votes
2answers
10k views

First and Last day of Week + Month in Twig

If i provide the week#, how might i go about getting the first day (and month) and the last day (and month) of that particular week? This week for instance would be April 26 and May 2 I know in PHP ...
6
votes
2answers
1k views

How can I display a "pending" entry in my "_entry" template?

I have an event site with dates in the future and past. I know how to display future entries as a listing: {% set entries = craft.entries.section('mySection').status('pending') %} But how do you ...
6
votes
1answer
2k views

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

I have the following code. {% spaceless %} {% for date in entry.d_date %} {% if date.showMonth == 1 %} {{ date.date.month }}- {% endif %} {% if date.showDate == 1 %} {{ date.date....
6
votes
2answers
1k views

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

I've got a plugin with some custom settings, like this: protected function defineSettings() { return array( 'serviceendpoint' => array(AttributeType::String, 'required'=>...
5
votes
2answers
590 views

How can I limit a list based on a custom date field

I a trying to display a simple event listing. I set up a custom date field called eventDate to note when the event happens. This code delivers me the list of events sorted by eventDate: {% for ...
5
votes
4answers
2k views

How to order by matrix field?

I have a section where its entries have a matrix field (matrixField). In the first matrix block there is a date field (dateField). I want to get my entries ordered by that date field. Is this possible?...
5
votes
1answer
861 views

Creating an archive page with full year and month list

Trying to create an archive page for each of my blog types within Craft. The page sorts by year and by month. (year and month are coming from my routes in this code.) By using the following, I can ...
5
votes
2answers
147 views

How do you replicate the EE {date_heading} tag pair in Craft?

I'm wondering how I would replicate the ExpressionEngine date_heading tag pair in Craft? {date_heading} {entry_date format="%Y %m %d"} {/date_heading} The date heading can be used to show a ...
5
votes
2answers
6k views

Adjust all date/times to users current timezone

I've done a bunch of research and I can't seem to find a suitable answer for this issue without hacking which I'd like to avoid. My client needs the entries in the DB to always assume they're ...
5
votes
2answers
574 views

How to set entries to auto-expire after certain # of days from post date?

Is there any way to set entries of an certain entry type to auto-expire after a certain number of days from the original post date?
5
votes
2answers
1k views

How to retrieve entries from two entry-types ordered by different date-fields?

I have two entry-types, 'Events' and 'Reports'. 'Events' have a matrix-field ('eventMultiDate') that allows authors to assign multiple dates to an event (recurring). 'Reports' have the default '...
5
votes
1answer
208 views

"Custom" validation for plugin settings page

I have a plugin that has a few settings. One of which is a start date and and end date. Everything is set up and working fine. I'd like to validate the start/end dates a a bit though. I am able to ...
4
votes
2answers
214 views

How do I get the next year?

I can get the current year in this way: {% set currentYear = now.year %} How do I get the next year?
4
votes
3answers
1k views

Display Entries in a calendar

I have a section for holding calendar entries stored by postDate in the CMS. On the front end I want to basically display these in a calendar. I have code which displays the calendar looping through ...
4
votes
1answer
166 views

Showing the month on an archive page

I've set up an archive page as described in the docs... so my archive page url looks something like this http://mysite.dev/news/2014/09. How do I then make the title display Archive for September ...
4
votes
1answer
449 views

Order Assets by date field

I have a page which lists assets by source. I've added a date field to the asset. How can I order the assets by this field so that the most recent is first? Here is my markup: {% set assets = craft....
4
votes
2answers
3k views

Is it possible to change the time increments in the Date/Time field?

We have a date/time field shown to render the time for a series of workshops but right now Craft only increments in 30 minutes. Is there a way for us to render 15 minute increments?
4
votes
1answer
587 views

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!
4
votes
1answer
370 views

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 ...
4
votes
2answers
7k views

Is it possible to output month names in my native language?

I'm doing this: {# Get events from `events` section in desired sort order #} {% set allEvents = craft.entries.section('events').order('eventsDate asc') %} {# Loop through `allEvents` and print the ...
3
votes
2answers
5k views

Get current date / time in specific timezone?

How can I get the current date / time for specific timezones? My local time is easy: {{ now|date("H:i") }} So how can I get this for New York? or Singapore?
3
votes
1answer
1k views

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

Currently using a date picker to select a date and submit it on user registration, formatted as m/d/Y, have played with various formats but can't one that works. Any ideas?
3
votes
3answers
2k views

How to display entries with a custom date field within month

I've got a date field, and I'm grabbing the month and year from the url. What I'm after is to display all the events within the month, but for some reason I can't get this to work {% set ...
3
votes
2answers
1k views

Entry Post Date Format time since - X days ago

Is there anyway to get my date formats looking like Facebook? I'd like to get my articles to have this as a date format: "5 min ago", "yesterday", "3 days ago", "4 months ago" and then once it reaches ...
3
votes
2answers
2k views

How to show entries which are live between dates regardless of postdate or expiry dates?

I'm trying to show live entries to user by selecting list of months in a dropdown. Some my entries are live for 2 or 3 months. I having trouble in finding right method. I have tried using after and ...
3
votes
2answers
395 views

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

Ok somebody ought to start asking the Totally Green questions, it may as well be me. How do I show the date and time an entry was last manipulated in the control panel? I produce video more than ...
3
votes
2answers
1k views

How can I group entries based on a dateTime field?

I am getting all entries from a section like this: // get the parent entry. {% set author = craft.entries.section('mySection').authorId(currentUser.id).first() %} // get the child entries from the ...
3
votes
1answer
175 views

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

I can do it in PHP, but I'm having trouble converting it to twig. Here's the PHP: $day = date("l"); date_default_timezone_set('America/Chicago'); if ($day == "Saturday") { echo "<p><b&...
3
votes
2answers
177 views

Show events until Midnight

I have a list of events which should list each event until midnight of said day. So If a gig happens at 17:00 it should still be visible until midnight of the same day. I came relatively close (I ...
3
votes
3answers
1k views

Expire an entry according to a date field

Ich have a concert entry which I want to expire after the concert is over. How do I do that? I was able to hide past entries like this: {% set present = now|date_modify("+1 day") %} {% for entry ...
3
votes
1answer
204 views

Change start of the week in Date Picker

A simple question with hopefully a simple answer. How can I make the date picker in the admin area start the week (i.e. each new line) with Mondays rather than Sundays? I'm sure it will just be a ...
3
votes
1answer
351 views

Date value different in CP and database

Have a site registering users. The user record in the CP says they registered at 11:39 June 12. The database 'dateCreated' says 10:39. The site settings timezone are UTC+1 BST. PHP config date....
3
votes
1answer
282 views

Display X minute / hours / days in entries

I am trying to print if statement for x time or x day ago for each published entries. For example the entry is posted x minutes ago should display x minutes ago or x hours ago. Same for days and ...

1
2 3 4 5