7

I am using the time manager for a set of data and I need to create a column in my attribute table of the date in the format yyyy-mm-dd. I already have a column in my attribute table that contains Julian days (e.g. values of 1, 2, 3, etc. that I want to correspond to 2010-01-01, 2010-01-02, 2010-01-3, etc. respectively). I've tried using the field calculator to do this using Converting from Julian Date to Calendar Date? but I was unable to get an output.

0

2 Answers 2

4

Another approach, assuming your Day 1 starts on 2010-01-01.

to_date(to_date('2010-01-01') + to_interval(concat(to_string(("j_day" - 1)), ' days')))

j_day is your Julian day field

4
  • Nicer, saves some typing
    – BERA
    Oct 13, 2017 at 7:10
  • Thanks @BERA I wish I could do programming ... it will be my New Year resolution next year...
    – Kazuhito
    Oct 13, 2017 at 7:22
  • Thanks! This is exactly what I was looking for. I'm unfamiliar with programming so this is more straightforward.
    – racheldeep
    Oct 13, 2017 at 17:09
  • Thanks @racheldeep for this interesting subject. It gave me opportunity to learn about calendar and Julian day (a.k.a. ordinal date).
    – Kazuhito
    Oct 13, 2017 at 22:44
3

Add a date field

Use Field Calculator with function editor (change the start date, dont know what you want) and press blue play button on top:

from qgis.core import *
from qgis.gui import *
import datetime

@qgsfunction(args='auto', group='Custom')
def jtogreg(x, feature, parent):
    startdate=datetime.datetime(2000,1,1)
    d=startdate+datetime.timedelta(x)
    return str(d)

enter image description here

The function can now be found under 'Custom'. Call the function:

 jtogreg(  "JDays" )

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.