Calculating days since start of year

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10412 Score: 0
    Jacob Sagrans
    Participant

    If anyone is interested in calculating days since the start of any given year from dates in CODAP, this demo document I prepared shows two possible ways of doing this using formulas (with one date attribute column, or with 3 columns for day, month, and year). The formulas calculate how many days into a given year a date was, taking into account leap years. This could be especially useful for things like phenology data, if you want to look at the time of year when something generally happens across multiple years. It is also possible to do such a conversion in Excel before importing the data into CODAP (for instance, see the instructions here).

    #10485
    Jacob Sagrans
    Participant

    I realized it might be useful to see the formulas for more generic attribute names, so here goes:If you have 3 columns/attributed titled “Day”, “Month”, and “Year”, use this formula (make sure month is indicated as a number like 12, NOT “December”, and for Year, give 4 digits, for example 2024, NOT 24):Day +if(Month> 1, 31, 0) +if(Month> 2, 28, 0) +if(Month> 3, 31, 0) +if(Month> 4, 30, 0) +if(Month> 5, 31, 0) +if(Month> 6, 30, 0) +if(Month> 7, 31, 0) +if(Month> 8, 31, 0) +if(Month> 9, 31, 0) +if(Month> 10, 31, 0) +if(Month> 11, 30, 0) +if(frac(Year/ 4) = 0 & Year> -47 & frac(Month/ 100) != 0 or frac(Month/ 400) = 0, 1, 0)If you have 1 column of date attribute type titled “Date”, use this formula:dayOfMonth(Date) +if(month(Date) > 1, 31, 0) +if(month(Date) > 2, 28, 0) +if(month(Date) > 3, 31,0) +if(month(Date) > 4, 30, 0) +if(month(Date) > 5, 31, 0) +if(month(Date) > 6, 30, 0) +if(month(Date) > 7, 31, 0) +if(month(Date) > 8, 31, 0) +if(month(Date) > 9, 31, 0) +if(month(Date) > 10, 31, 0) +if(month(Date) > 11, 30, 0) +if(year(Date) < -46, 0,if(frac(year(Date) / 400) = 0, 1,if(frac(year(Date) / 100) = 0, 0,if(frac(year(Date) / 4) = 0, 1, 0))))

    #10484
    Jacob Sagrans
    Participant

    I realized it would likely be more helpful to have these formulas use more generic attribute names (“Day,” “Month,” “Year” and “Date”) so you could copy/paste the formulas into other CODAP documents without potentially having to change anything in the formulas. So I updated this demo document accordingly. See here.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.