Forum

Thread tagged as: Problem, Api, Runway

Runway - Importing dates

I have been happily creating items in a collection (through the admin pages) that have a date field - quite a basic field:

<perch:content id="gamedate" label="Game Date" type="date" title="true" />

The date is saved in the database as 2017-03-24 for example.

I've been creating an import script to get a whole load of entries into the same collection - the dates are being imported from a CSV in the same format - 2010-09-04. This date is saved in the database as 2010-09-04 00:00:00 (Using the same template above as the basis for the import).

One of my pages is filtering the items by the date, but as they can end up being stored in two different formats, the query doesn't always return the correct result. The date to filter by is being passed in the url in the format 2010-09-04

I can get round this by adjusting my filter to look for both formats:

'filter' => 'gamedate',
'match' => 'in',
'value' => perch_get('gamedate').','.perch_get('gamedate').' 00:00:00'

but this doesn't "feel right" having the date being stored in two formats for similar items.

EDIT:
Runway 3.0.14
PHP 7.1
MariaDB 10.2

Duncan Revell

Duncan Revell 78 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

How are you specifying the date when you import?

Duncan Revell

Duncan Revell 78 points
Registered Developer

Importing from a CSV file, so the date is a string (2010-09-04). Using fgetcsv to grab each line, then passing the array value to the importer:

while (($line = fgetcsv($file)) !== false) {
                //$line is an array of the csv elements
                $result = $Importer->add_item([
                    'gamedate'      => $line[4],
                    'opposition'    => $line[2],
etc, etc
Drew McLellan

Drew McLellan 2638 points
Perch Support

Hmm, ok, I'll run some tests. I don't think we should be appending a time if time="true" isn't set on the template tag.