Not showing dates for Sunday

Hi all

I have a small function which returns events only for the current week. Works good. The problem is, that the events for Sunday do not show? Even when I have events for Sunday, wondering what I need to change so this will list events for Monday-Sunday and not just Monday-Saturday.


  // Snippet for showing events for current week
  $dow = date('N');
  if ( $dow == 7 ) { // Sunday
    $offset = 'today';
  } else {
    $offset = 'sunday';

In action:

->fieldCondition('field_event_date', 'value', date("Y-m-d",strtotime($offset)), '<')

Any ideas?

Thanks, Barry

What’s the reason for the special handling of Sunday in terms of setting $offset differently? That is, if you just leave $offset as “today” each time, does it make any difference?

Good question. I’m not really sure, I had help creating this sometime back from another thread.
If I remove $offset = ‘sunday’ and just keep today, no events show?

Thnaks, Barry

Could it be that the “<” in the final parameter when you call the function is actually saying “return all the events where the date is less than the date specified in the third parameter”, and the special handling is to make sure that if called on a Sunday, it returns the next week rather than no events at all? Perhaps if you change that to “<=” it might do what you want?

Failing that I think we’d need to see the code for the function.

If today was Sunday and we have events for next week, those events will not show until 12:01am monday morning. I changed >= though nothing changes.


Can’t really see any more without knowing what fieldCondition() does. Presumably that’s the function that displays the events based on the date you pass in to it?

Correct. I’ll see what other code there is I can show you.
In the meantime, as things stand, are you saying with the code we have excluding the extra fieldcondition that events for mon-sun should be showing?

Thanks, Barry

I can’t see how to know, to be honest, which might be my lack of experience as much as anything else. All we know is that you’re calling a function and passing in two parameters that might be column names, along with either today’s date if it’s Sunday, or next Sunday’s date if it isn’t, and a less-than symbol. One might assume that means we’re telling some code to compare “field_event_date” with the date we passed in, and if it’s lower, perform some action.

I am surprised that changing “<” to “<=” didn’t help, but then I’m only guessing at how the rows are selected.

That said, now I’ve done a quick Google on ‘fieldCondition’ it seems this is Drupal and, while I’ve heard of it, I don’t know anything about it.

Try changing ‘today’ to ‘now’ and ‘sunday’ to ‘next Sunday’ and see if that makes any difference.

I was myself, I thought this would work, though nothing changes.

Tried this, again, nothing changes, no errors everything is the same.

As droopsnoot mentioned, this is on the Drupal platform, though this shouldn’t be an issue.
Here is the two condition I have underneth my first snippet:

->fieldCondition('field_event_date', 'value', date("Y-m-d"), '>') // end date after today
->fieldCondition('field_event_date', 'value', date("Y-m-d",strtotime($offset)), '<')

If I change < to > in the second condition, the events are listed from next week starting with Sunday, instead of Monday. We need to tweak something so we make up the lost/missing day.

What do you think?

Thanks, Barry

So when this is set to today (or now) it becomes equivalent to the value used in the first condition and you are looki9ng for entries that are both < and > than today at the same time ( which of course means no results.

The first condition is so I don’t show any old events, I use this same condition in another function which shows all the events over the full year. And in this instance, I’m adding the second condition to narrow things down so I only show events/dates for this week.

Everything works ok, besides Sunday events.

What do you suggest felgall, is this a easy fix?

Cheers, Barry

What happens if you change the first condition to >=

Yes I’ve already tried this felgall, multiple combinations, with, without, on its own… nothing changes.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.