I don't know if this is a problem with me, views2, or date, and I can't tell if it's similar to drupal.org/node/233805.

When I create a views argument for a timedate field, and tell it to use the argument @P100Y, it generates this SQL - I think the FROM_UNIXTIME calls should be dropped to get the right result.

SELECT node.nid AS nid
 FROM node node 
 LEFT JOIN content_type_eventfordisplay node_data_field_eventdate ON node.vid = node_data_field_eventdate.vid
 WHERE (node.type in ('eventfordisplay')) AND ((FROM_UNIXTIME(node_data_field_eventdate.field_eventdate_value) + INTERVAL -18000 SECOND)>='2008-05-23 00:00:00') AND ((FROM_UNIXTIME(node_data_field_eventdate.field_eventdate_value) + INTERVAL -18000 SECOND)<='2108-05-23 00:00:00')

I'm attaching the exported view.

CommentFileSizeAuthor
view-datetime.txt3.71 KBonhover

Comments

choster’s picture

This might be the problem I am experiencing as well: http://drupal.org/node/260550 ; I filed it under views and it was moved back to date.

The FROM_UNIXTIME is found both date_api_sql.inc and line 1070 of views.module.

karens’s picture

Status: Active » Postponed (maintainer needs more info)

Move to the latest dev version and see if you still have problems. There have been a number of changes since beta 1.

onhover’s picture

Karen, I tried accomplishing by filter and argument, both still show same problem. Downloaded the newest drupal6, cck, date, and views today.

I believe this is the same or closely related to choster's 260550 that you updated today.

I set up a content type "comingevents" with a datetime field. I want to create a view so that only those nodes where the datetime field is higer than the current time can display. I tried both a filter and an argument. In both cases, views generates SQL callig FROM_UNIXTIME on the field. CCK has stored the value as a datetime field. The views don't have any results. I believe the problem is the calls to "FROM_UNIXTIME".

Not that it's likely to be of much interest, but just in case, here's the generated sql:

SELECT node.nid AS nid
 FROM dhead1_node node 
 LEFT JOIN dhead1_content_type_comingevent node_data_field_dateofevent ON node.vid = node_data_field_dateofevent.vid
 WHERE (node.type in ('comingevent')) AND (EXTRACT(YEAR FROM((FROM_UNIXTIME(node_data_field_dateofevent.field_dateofevent_value) + INTERVAL -18000 SECOND))) > EXTRACT(YEAR FROM(NOW()))) AND (EXTRACT(MONTH FROM((FROM_UNIXTIME(node_data_field_dateofevent.field_dateofevent_value) + INTERVAL -18000 SECOND))) > EXTRACT(MONTH FROM(NOW()))) AND (EXTRACT(DAY FROM((FROM_UNIXTIME(node_data_field_dateofevent.field_dateofevent_value) + INTERVAL -18000 SECOND))) > EXTRACT(DAY FROM(NOW()))) AND (EXTRACT(HOUR FROM((FROM_UNIXTIME(node_data_field_dateofevent.field_dateofevent_value) + INTERVAL -18000 SECOND))) > EXTRACT(HOUR FROM(NOW()))) AND (EXTRACT(MINUTE FROM((FROM_UNIXTIME(node_data_field_dateofevent.field_dateofevent_value) + INTERVAL -18000 SECOND))) > EXTRACT(MINUTE FROM(NOW()))) AND (EXTRACT(SECOND FROM((FROM_UNIXTIME(node_data_field_dateofevent.field_dateofevent_value) + INTERVAL -18000 SECOND))) > EXTRACT(SECOND FROM(NOW())))

When I set up an argument:

SELECT node.nid AS nid
 FROM dhead1_node node 
 LEFT JOIN dhead1_content_type_comingevent node_data_field_dateofevent ON node.vid = node_data_field_dateofevent.vid
 WHERE (node.type in ('comingevent')) AND ((FROM_UNIXTIME(node_data_field_dateofevent.field_dateofevent_value) + INTERVAL -18000 SECOND)>='2008-05-28 22:41:00') AND ((FROM_UNIXTIME(node_data_field_dateofevent.field_dateofevent_value) + INTERVAL -18000 SECOND)<='2108-05-28 22:41:00')
onhover’s picture

Version: 6.x-1.0-beta » 6.x-2.x-dev
onhover’s picture

In date_views.inc, in the function sql_field, I commented out the call to FROM_UNIXTIME($field) for data types that need it. Then the view I had designed worked as I wanted it to.

SO, I conclude that, in that function, $this->datetype is mis-set to "int". I don't think I have the expertise to track down why this is happening.

Thanks

  // date_views.inc from May 28 
  function sql_field($field, $set_offset = NULL) {
    if ($field == 'NOW()') {
      return $field;
    }
    $offset = $set_offset !== NULL ? $set_offset : views_get_timezone();
    switch ($this->db_type) {
      case 'mysql':
      case 'mysqli':
        switch ($this->date_type) {
          case 'int':
            // $field = "FROM_UNIXTIME($field)";
	    // commented out the above and my datetime-based view worked
karens’s picture

Status: Postponed (maintainer needs more info) » Fixed

I just released a new 6.2-beta2 version for Date, so update to the latest code for Date and also get the latest -dev version of the Views module, which has some date-related changes that are needed for the Date views handling. If you use the Calendar module, get the new 6.2-beta2 version of that as well.

If you still have problems after that, open a new issue marked with the beta2 version so I know it's still a problem there.

Fanvik’s picture

In beta3 this problem is still here.

Fanvik’s picture

Version: 6.x-2.x-dev » 6.x-2.0-beta3

In beta3 this problem is still here.

karens’s picture

That's the problem -- date_views.inc is no longer needed and has been removed, but you have an older copy floating around and it is doing the wrong things. I just made a new commit that creates a blank date_views.inc file so this won't happen.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

osocurioso’s picture

I have the same problem as onhover with FROM_UNIXTIME applied to MySQL datetime datatypes in beta3, and as far as I can tell, there is no date_views.inc in my installation (I started with a fresh install using beta3).

The relevant part of date_api_sql.inc reads:

    146   function sql_field($field, $offset = NULL) {
    147     if (strtoupper($field) == 'NOW') {
    148       // NOW() will be in UTC since that is what we set the db timezone to.
    149       $this->local_timezone = 'UTC';
    150       return 'NOW()';
    151     }
    152     switch ($this->db_type) {
    153       case 'mysql':
    154       case 'mysqli':
    155         switch ($this->date_type) {
    156           case DATE_UNIX:
    157             $field = "FROM_UNIXTIME($field)";
    158             break;
    159           case DATE_ISO:
    160             $field = "STR_TO_DATE($field, '%Y-%m-%%dT%T')";
    161             break;
    162           case DATE_DATETIME:
    163             break;
    164         }
    165         break;

However, it seems as though the type of the date field (line 155) is not recognized as DATE_DATETIME even though it is stored as a MySQL datetime type. I tried to find out where/how $this->date_type was assigned its value, but due to unfamiliarity with both Drupal and PHP I didn't get very far along that track.

For reference, the generated SQL in my case is:

SELECT node.nid AS nid,
   node_data_field_start_time.field_start_time_value AS node_data_field_start_time_field_start_time_value,
   node.type AS node_type,
   node_data_field_start_time.field_start_time_value2 AS node_data_field_start_time_field_start_time_value2,
   node_data_field_start_time.nid AS node_data_field_start_time_nid,
   node_revisions.teaser AS node_revisions_teaser,
   node_revisions.format AS node_revisions_format,
   node.title AS node_title
 FROM node node 
 LEFT JOIN content_type_program node_data_field_start_time ON node.vid = node_data_field_start_time.vid
 LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
 WHERE (node.type in ('program')) AND (FROM_UNIXTIME(node_data_field_start_time.field_start_time_value) >= NOW())
 ORDER BY node_data_field_start_time_field_start_time_value ASC

where node_data_field_start_time.field_start_time_value is a MySQL datetime field defined through CCK.

karens’s picture

Beta3 is out of date, you need to use the latest -dev code. And this is a closed issue.

wundo’s picture

Priority: Normal » Critical
Status: Closed (fixed) » Active

If beta3 is outdated, the best thing to do is release beta4, don't you think?

wundo’s picture

Status: Active » Closed (fixed)

I've just created a feature request about that.