Skip to main content
1 of 4
Ben W
  • 23.1k
  • 3
  • 19
  • 43

I would use PyQGIS with the datetime and csv modules for this. Copy and paste the script below into a new editor in the Python console. You will just need to edit the output path for the CSV file, then select your gpkg as the active layer and run the script.

from datetime import datetime, timedelta

import csv

# Edit the line below to the path where you want your output csv written
output_csv = 'Path/To/Attributes.csv'

lyr = iface.activeLayer()

string_flds = [fld.name() for fld in lyr.fields() if fld.type() == QVariant.String]

if string_flds:
    fld_name = string_flds[0]
    
    csv_tbl = open(output_csv, mode='w', newline='')
    writer = csv.writer(csv_tbl)
    writer.writerow(['Column1', 'Column2'])

    for ft in lyr.getFeatures():
        attr = ft[fld_name]
        start_date_txt = attr.split('to')[0][-11:][:-1]
        start_date = datetime.strptime(start_date_txt, '%Y_%m_%d').date()
        writer.writerow([attr, start_date_txt])
        end_date_txt = attr.split('to')[1][1:]
        end_date = datetime.strptime(end_date_txt, '%Y_%m_%d').date()
        gaps = end_date - start_date
        gap_days = gaps.days-1
        day_count = 1
        for i in range(gap_days):
            fill_date = start_date+timedelta(days=day_count)
            fill_date_txt = datetime.strftime(fill_date, '%Y_%m_%d')
            writer.writerow([attr, fill_date_txt])
            day_count+=1
        writer.writerow([attr, end_date_txt])
        
    csv_tbl.close()
    del writer

print('Done')

I tested with this dummy geopackage (one string field containing the information).

enter image description here

After running the above script (shown here in the Python console)

enter image description here

The output CSV file was produced:

enter image description here

Ben W
  • 23.1k
  • 3
  • 19
  • 43