Date type computed field

afsladmin - July 18, 2008 - 16:16
Project:Computed Field
Version:5.x-1.2
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

It would be really useful for me if computed field could store/calculate dates.

#1

willwade - July 22, 2008 - 15:02

Im only guessing here but I'm pretty sure you can already. First install the date module with cck. http://drupal.org/project/date Create a field. Call it datetest

the variables you can use for computed field are in the format of

        $node->field_datetest[0]['value']
            2008-07-17 01:30:00
        $node->field_datetest[0]['value2']
            2008-07-17 01:30:00
        $node->field_datetest[0]['view']
            <span class="date-display-single">17/07/2008 01:30</span>

use datestamp and your variables will probably be a little easier to work with

#2

afsladmin - July 19, 2008 - 21:11

Thanks for this suggestion. I have the date module installed. But when I create the computed field, the only data types it makes available are int, float, varchar, text and longtext. Which one of these should I choose, and what data length?

I want to use the computed field in a view filter condition, comparing it with now(), but I guess the view module won't provide me with this option unless the field has a date type?

#3

willwade - July 22, 2008 - 15:02

Apologies. I just realised your query is regarding 5.x. The demo I suggested was using in the 6 release (that is work-in-progress: http://drupal.org/node/236963) . Having never previously played around with date before now Im not sure whats possible - I would have thought what you want to do is possible though.. I'll try and find 10 minutes this evening to see whats possible on 5.

#4

emdalton - March 23, 2009 - 15:34

I need this as well, to fix a bug in the new version of Event (on 5.x). This version of Event doesn't expose start dates to Views. I can echo the value of the start date to a computed field, but I need to compare it to "now" in Views to get the right results. For that, the computed field needs to be able to indicate to Views that it is a date. I'm willing to try to hack the code, but I need some hints.

#5

Zorga Lina - June 17, 2009 - 17:02

Re: computed field, (and other CCK fields), at least in 5.0 the data type determines what kind of filtering and other View operators you can use - I wish that CCK fields were not typed so strongly, considering that PHP itself is not, and in fact, date fields end up as varchar(20) in the database when you create the 'date' field type. Even if you format the computed field just like a date, you can't use the View operations that are tied to the 'date' type.
Computed field only gives you GTLT (as alpha or numeric comparison).
I thought I would try to make it possible to use the 'date' View handler and operators for my computed field, too, but I would need to signal somehow that I wished to use the 'date' filtering BEFORE the user enters any options, maybe using the name of the computed field (if _date is part of the name) but that is not very reliable and public-friendly coding, and I didn't want to write something that isn't going to be reusable. I knew that changing the field 'type' from 'computed' to 'date' would break the 'computed' mechanism.
I created a proxy CCK Date field, call it field_proxy_date, and in my 'computed field' code, I set the value of field_proxy_date (although the Computed field documentation doesn't say this, you can set OTHER node field values than the computed field itself. Perhaps this is a security risk, but it worked as a hack/workaround and now I have a 'computed' date field which I can use in Views as I wish).

#6

tandersonmd - June 18, 2009 - 23:24

Can you provide a code example you would use to set the value of the field other than the computed field itself?

Thanks!

 
 

Drupal is a registered trademark of Dries Buytaert.