<p>Just in case anyone else comes across this problem in the future I actually managed to figure it out myself.</p>

<p>I created kept the fieldtype as a DateTime field and grabbed the date/time and the extra value within the prepValueFromPost function then pushed the extra data into a custom table and post just the datetime to the craft_contents table.</p>

<p>Then within the getInputHtml function I grabbed the extra data from the custom table to display along with the date/time.</p>

CC BY-SA 3.0
2017-03-03T14:01:41.197Z
2017-03-03T14:01:41.197Z
wizzer711
<p>I wish to have a custom fieldtype which contains the standard datetime field abilities along with storing an extra piece of data. I have created a custom fieldtype for this with a mixed attributetype to store the data as JSON.</p>

<p>However I am having problems when I try to query some of the data from the frontend.</p>

<p>For example to pull out a specific piece of data I am currently doing:</p>

<pre><code>variableName.date
</code></pre>

<p>This correctly pulls out the date I have stored. However when using this in the example:</p>

<pre><code>craft.entries({ type: 'sectionName', customFieldtype.date: '&gt;=' ~ now|date(c) }).order('customFieldtype.date asc').first()
</code></pre>

<p>I get errors as when Craft converts this to SQL it's converting these to column names and customFieldtype.date doesn't exist.</p>

<p>Is there any way around this bar having to re-create the built in craft entries calls in pure SQL?</p>

<datetime><custom-fieldtype>
Using data within a mixed attribute type to query Craft entries dates
# Using data within a mixed attribute type to query Craft entries dates

(Asked by: username_0 on 2017-03-01)

I wish to have a custom fieldtype which contains the standard datetime field abilities along with storing an extra piece of data. I have created a custom fieldtype for this with a mixed attributetype to store the data as JSON.
However I am having problems when I try to query some of the data from the frontend.
For example to pull out a specific piece of data I am currently doing:
variableName.date

This correctly pulls out the date I have stored. However when using this in the example:
craft.entries({ type: 'sectionName', customFieldtype.date: '>=' ~ now|date(c) }).order('customFieldtype.date asc').first()

I get errors as when Craft converts this to SQL it's converting these to column names and customFieldtype.date doesn't exist.
Is there any way around this bar having to re-create the built in craft entries calls in pure SQL?

**Tags:** datetime, custom-fieldtype


---

## 1 answers

### Answer by username_0 on 2017-03-03. Score: 2

Just in case anyone else comes across this problem in the future I actually managed to figure it out myself.

I created kept the fieldtype as a DateTime field and grabbed the date/time and the extra value within the prepValueFromPost function then pushed the extra data into a custom table and post just the datetime to the craft\_contents table.

Then within the getInputHtml function I grabbed the extra data from the custom table to display along with the date/time.


---

