Doesn't seem to be an issue with the Date field since if I set an absolute date, it works just fine. basically I'm trying to make a view of "upcoming events" where only Event Dates greater or equal to "now" show up. Looking at the query, it appears as though its just not responding to the 'now' relative date. am I missing something here?

Filters
Node: Type in Course, Event
Settings
Date: Date Content: Date (field_date) - From date >= now

query:

SELECT node.nid AS nid
 FROM node node 
 LEFT JOIN comments comments ON node.nid = comments.nid
 WHERE node.type in ('course', 'event')

Thanks in advance!

Comments

merlinofchaos’s picture

Project: Views (for Drupal 7) » Date
Version: 6.x-2.5 » 6.x-2.x-dev
Component: page displays » Miscellaneous
steinmb’s picture

Hi
I have the same issue. Upgrading to date-6.x-2.x-dev (21 April) did not solve the problem. Looking at the query used I'll find that now is "2009-01-01"

 WHERE ((node.status <> 0) AND (node.type in ('event')))
   AND (DATE_FORMAT(node_data_field_time.field_time_value, '%Y-%m-%d') >= '2009-01-01')
   ORDER BY node_data_field_time_field_time_value ASC

Searching issues you will find several similar issues. Some claim that it is supposed to be fixed in the latest date-dev release but for me is that not the case. Pls. read http://drupal.org/node/386406

steinmb’s picture

Did some more testing, followed all the debugging steps found on the date module project page. To me this look like a serious problem, not sure where I should start looking, Date, Views or CCK? Is it date-API that provide view with relative date information? I tested my PHP installation and "strtotime("now")" is returning the correct value as far as I can see.

--
Steinmb

scrypter’s picture

I too got desparate with this problem. I have read ALL previous posts on this issue, and still believe it is a bug. I put this one line of code into the date_api_filter_handler.inc file in the date_filter() function
if ($this->value['default_date'] == 'now') $this->force_value = TRUE; just before this line:
$value_parts = !is_array($this->value[$prefix]) ? array($this->value[$prefix]) : $this->value[$prefix]; and it seems to fix it!
Sorry I have'nt rolled a patch, this "fix" could be a really bad idea, but it got me out of a hole. Maybe it will be a clue for Karen? I was not exposing this filter. I tried the latest dev, but got other errors (foreach!) so went back to circa 30 March 09 release. BTW, Calendar is a fantastic module, thanks so much.

steinmb’s picture

Thanx! Yes it look like a bug that is only partly fixed since the last changes in date-dev fixed this issue for some but not all. However your "oneliner fix" did not do it for me... I'll still have 2009-01-01. Just be sure have I tested date_now() in a page.tpl.php with:

<?php
  $today = date_format(date_now(date_default_timezone_name()), ''Y-m-d'');
   print $today;
?>

And it is returning the correct date and format as expected. Since the code is able to find what year it is some of it have to be working right? Is it the fuction $year_range() that generate the year? I have also had a look on the format the data in the table "field_time_value" are stored in: 2009-03-04 22:00:00

I hope KarenS read this and are able to give us some pointers to solve this issue in this awesome module :)

Cheers
Steinmb

scrypter’s picture

I am assuming 'now' is all lower case. Should really be strtoupper($this->value['default_date']) == 'NOW'. Doubt that this is your problem though. Because the preview shows the sql generated and the WHERE clause is perfect if you enter today's date (2009-04-27) and missing if you use 'now', I think the problem is in the sql generator, date_api_sql.inc and/or date_api_filter_handler.inc. I spent hours putting in print_r();die; all over the place to debug before arriving at the "fix". A lot of the comments on the same issue say it works if the filter is exposed, which sort of confirms I am possibly on the right track? If you use preview, do you see the sql? It sounds like the WHERE clause is there for you with the 2009-01-01 date. For me, it was completely absent.

steinmb’s picture

I needed to take a step back and sum up the result of the last 24 hours of debugging. And this is the result of me not working at 4am. Views, CCK, Calendar are all running stable releases.

If you create the date filter and leave "Date default:" field empty you will get buy running:
Date 6.x-2.1

WHERE (node.status <> 0) AND (node.type in ('event'))
 ORDER BY node_data_field_time_field_time_value ASC

6.x-2.x-dev 2009-Apr-21

WHERE ((node.status <> 0) AND (node.type in ('event')))
 AND (DATE_FORMAT(node_data_field_time.field_time_value, '%Y-%m-%d') >= '2009-01-01')
 ORDER BY node_data_field_time_field_time_value ASC

Entering 'now' into "Date default:" you will get with:
Date 6.x-2.1

WHERE (node.status <> 0) AND (node.type in ('event'))
 ORDER BY node_data_field_time_field_time_value ASC

6.x-2.x-dev 2009-Apr-21

WHERE ((node.status <> 0) AND (node.type in ('event')))
 AND (DATE_FORMAT(node_data_field_time.field_time_value, '%Y-%m-%d') >= '2009-04-27')
 ORDER BY node_data_field_time_field_time_value ASC

It is working on the last dev. release but if you omit entering 'now' the system by magic uses 2009-01-01. Is this as designed?

--
Steinmb
http://smbjorklund.com

sahuni’s picture

It's working for english version but not for translated version.
I tested french and English.

ksc’s picture

I´m not quite sure if it´s the same issue.

In VIEWS/filters the select list (or whatever should show up) for "Relative value" doesn´t show up.
I need to set up a view "Is greater than now"

I tested with 6.x-2.1 and 6.x-2.x-dev (2009-apr-21)

seancorrales’s picture

Had the same problem as reported - using "now" did not put an entry into the SQL or limit the results. I was using the latest stable release but grabbed the latest DEV version (per #7's recommendations) and that fixed the issue.

steinmb’s picture

Unable to reproduce the problem in #8. Enabled Norwegian and English but the view was still working. Verify that 'now' are still present after changing the site language.

--
Steinmb

steinmb’s picture

Hi
#9 Did you enter 'now' into Date default-form? What is the query output for the display you have created?

ksc’s picture

That was my fault. I thought there is a select list to chose from.
I have got the point. It works fine. Thanks!

bluemuse’s picture

I have the same problem even with the latest dev version.

Past Events set to display From Date < = now. It shows all events.
Upcoming Events page set to display To Date > = now. It shows all events.

The absolute date field works, but we don't want to have to do this manually.

steinmb’s picture

@blue_muse: How does the query look that Views created?

bluemuse’s picture

If I put 'now' in the Date default field, and leave the drop downs as is:

 WHERE (node.type in ('events')) AND (node.status <> 0)
   ORDER BY node_data_field_date_field_date_value ASC

If I use the drop downs to set the date to May 1, 2009 and skip the Date default field:

 WHERE ((node.type in ('events')) AND (node.status <> 0))
    AND (DATE_FORMAT(ADDTIME(node_data_field_date.field_date_value, SEC_TO_TIME(-25200)), '%Y-%m-%d\T%H') <= '2009-05-01T00')
   ORDER BY node_data_field_date_field_date_value ASC
sahuni’s picture

Now it's ok for me, same in English and French, with 6.2.dev.
I had to delete filter and rebuild it for french version which was existing before. Now, when filtering, I can choose date(node), then my CCK date field.
So no issues on my part. Thanks for considering my request.
All the best

steinmb’s picture

@blue_muse: What PHP release are you running? Remember to flush the view cache. Also try following the troubleshooting steps on the Date module project page.

bluemuse’s picture

@steinmb Thanks for following up with me. PHP Version 5.2.6, I flushed the views cache and tried the whole list on the troubleshooting section of the Date page (just did this again to be certain). I'm still getting the following query when I use <=now for the From Date.

I post it in full here in case there's something else in the view that is causing this problem:

SELECT DISTINCT(node.nid) AS nid,
   node.title AS node_title,
   node_data_field_date.field_date_value AS node_data_field_date_field_date_value,
   node_data_field_date.field_date_value2 AS node_data_field_date_field_date_value2,
   node_data_field_date.delta AS node_data_field_date_delta,
   node.type AS node_type,
   node.vid AS node_vid,
   node_revisions.body AS node_revisions_body,
   node_revisions.format AS node_revisions_format
 FROM node node 
 INNER JOIN users users ON node.uid = users.uid
 LEFT JOIN content_field_date node_data_field_date ON node.vid = node_data_field_date.vid
 LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
 WHERE (node.type in ('events')) AND (node.status <> 0)
   ORDER BY node_data_field_date_field_date_value ASC
bluemuse’s picture

double post.

karens’s picture

Status: Active » Closed (duplicate)

This is a duplicate of #432368: Problems with exposed date filter, which I'm unable to reproduce in the latest -dev code. If you have problems in the latest -dev code, follow up on that issue.

derEremit’s picture

this is fixed for me with latest -dev
problem appears in 2.1

bluemuse’s picture

@KarenS Thanks for the info. I'm going to go through everything again to make sure I'm not missing something. When I've finished, I'll post anything I find to #432368

Oh, and thanks for the great module. It works great except for this one instance.

WildKitten’s picture

@scrypter #4

Thank you mate! This fixed my problem.