2

I have a view in which I want to display posts that I made on this date 10 years ago. I can get close but not exactly what I want by setting the view's filter to the following:

"Authored On is between: (offset) -10 year and -10 year +1 day"

My problem is that if it's currently 1pm on Dec. 17, 2019, I want to see all posts from the Dec. 17, 2009, regardless of hour posted. Instead I am seeing posts from Dec. 16, 2009 1pm to Dec. 17, 2009 1pm. I don't care what time the post was authored at, I just want it to show if the calendar day from 10 years ago is the same.

How can I set up my filter to do this?

2

Like you did, create two filters for the date range and then use the following values

-10 years midnight 
-10 years +1 day midnight

Remember to select

An offset from the current time such as "+1 day" or "-2 hours -30 minutes" 

If you want to do this programmatically you can create a date filter and set the actual date values from code for the filter range.

You can create the date filter and set the filter value programmatically like the following

How do I programmatically render a view that has exposed filters?

|improve this answer|||||
  • Um, that question has no accepted answer. I don't want an exposed filter or a contextual filter. I am looking for a way to do this in the standard (for dummies like me) Views interface under Filter Criteria. – Tantalus Dec 17 '19 at 20:26
  • @Tantalus - I have updated the answer with something you can do without code. Can you please check if this works for you? – anoopjohn Dec 17 '19 at 21:18
  • I think this is probably right. It's not exactly working in my Drupal install. Today is the 17th and I am still seeing items from the 16th. But, when I use your format in a tiny php file like this <?php echo date('F j, Y g:i a', strtotime('-10 year midnight')); ?> is outputs exactly the correct time. This leads me to think that maybe my Drupal install or local dev environment is not set up for my correct timezone. – Tantalus Dec 17 '19 at 22:59
  • Well, I checked my timezone settings and everything is set to CST. I have it working now with the following: -10 year +1 day midnight to -10 year +1 day midnight +25 hours. I tested by creating backdated posts at 12:01am 2009/12/17 and 11:59pm 2009/12/17. I have no idea why this worked and yours didn't. Maybe leap years? I can live with this, and I'll mark your answer as correct. It got me moving in the right direction at least. – Tantalus Dec 17 '19 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.