ordinal day?

Tagged: 

Viewing 16 reply threads
  • Author
    Posts
  • May 23, 2026 at 1:33 PM #54168

    Glen Forister
    Participant

    I’m trying Dto change field (Date and Time) input to Julian day plus time to make a number with a decimal.

    I was once told:
    =======================
    Try using:
    DAYOFYEAR([Date Collected])
    This function directly returns the Julian day (1–365) without crashing TF5.
    ========================
    See attached, I’ve tried both text and number result.

    Attachments:
    You must be logged in to view attached files.
    May 23, 2026 at 8:29 PM #54170

    Brendan
    Keymaster

    Remove the square brackets [ ] from your formula.

    May 24, 2026 at 9:48 AM #54173

    Glen Forister
    Participant

    That didn’t work. I tried the formula on both col 1 (full date and time) and DMY with both text and number conditions. See attached.

    Attachments:
    You must be logged in to view attached files.
    May 26, 2026 at 1:47 PM #54190

    Daniel Leu
    Participant

    What kind of type does the DMY calculation return?

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    May 26, 2026 at 2:05 PM #54191

    Glen Forister
    Participant

    What I showed above was DMY = text. I changed it to number and date and neither made a difference. I also changed the DayofYr to both number and text. Nothing works.

    May 28, 2026 at 12:29 AM #54196

    Brendan
    Keymaster

    Where did you get the info for the DAYOFYEAR() function? It is not a function I have in the formula editor.

    Have you tried JavaScript to generate that?

    Thanks,

    Brendan

    May 28, 2026 at 8:54 AM #54201

    Glen Forister
    Participant

    I don’t remember what form I was using when I was given that instruction (I keep that now) in my notes (questions TapForms). It could have been a script.
    I don’t care how I do it, you can see what i’m trying to do which is given the input from “Date & Time” in the first col., I want a day of year + a decimal for the time of day (hours & minutes).

    This is so I can graph Date & Time against what happens on that event which is from a number from 1-6.

    Thanks for looking.

    May 28, 2026 at 9:09 PM #54204

    Brendan
    Keymaster

    Here’s a JavaScript function which will give you the day of the year:

    const dayOfYear = date => {
        const myDate = new Date(date);
        const year = myDate.getFullYear();
        const firstJan = new Date(year, 0, 1);
        const differenceInMillieSeconds = myDate - firstJan;
        return (differenceInMillieSeconds / (1000 * 60 * 60 * 24) + 1);
    };
    
    const result = dayOfYear("2019-2-01");

    For the time of day, you can call myDate.getHours(), myDate.getMinutes(), myDate.getSeconds()

    May 29, 2026 at 9:47 AM #54206

    Glen Forister
    Participant

    Well, That didn’t do anything. See attached.
    I tried it inserting my Date in the left col. for Date in the first line = no result.
    I replaced 3 occcurances of “Date” with my Date in the left col. = no result

    Both of these I had the result type as “Number, Text & Date. No result from any of these.

    I added the Field format as Decimal style = no result.

    What needs to be done?
    Thanks.

    Attachments:
    You must be logged in to view attached files.
    May 29, 2026 at 6:30 PM #54208

    Brendan
    Keymaster

    That’s a script for a Script Field. It’s not a formula for the Calculation Field.

    You need to also call return result; at the end of the script.

    But you also need to pass in your field’s date.

    Here’s a more full example:

    function Day_Number() {
    
        const dayOfYear = myDate => {
            const year = myDate.getFullYear();
            const firstJan = new Date(year, 0, 1);
            const differenceInMillieSeconds = myDate - firstJan;
            return (differenceInMillieSeconds / (1000 * 60 * 60 * 24));
        };
        var date_id = 'fld-22b8461cd7e14fbc988ecd1b7b22a013';
        let my_field_date = record.getFieldValue(date_id);
    
        const result = dayOfYear(my_field_date);
        return result.toFixed(0);
    
    }
    
    Day_Number();

    You’ll need to replace the date_id (‘fld-22b8461cd7e14fbc988ecd1b7b22a013’) with your Date field’s Field ID.

    May 30, 2026 at 10:15 AM #54214

    Glen Forister
    Participant

    OMG, how did I miss using the script window instead of the calc. I’m sorry. Just haven’t had to edit a script in a while I guess.

    I changed the field type to SCRIPT.
    I bring up the SCRIPT window and it has an example starting script. I can delete it, but I can’t past into the winddow the script you supplied.
    If I try to type it, I’ll have many mistakes to weed out and that will be a big waste of both of our time.
    How can I paste something into that SCRIPT window. I remember not being able to add the fld- number by copy and paste, but I never complained about that until now.

    May 30, 2026 at 8:08 PM #54217

    Brendan
    Keymaster

    Use the Paste as Plain Text option under the Edit menu.

    May 31, 2026 at 1:50 PM #54219

    Glen Forister
    Participant

    I got the script to work, thanks. BUT, not all dayofyear values are the same for multiple records of the same day. What does that, to be off a day?
    Thanks for sticking with me on this.

    Attachments:
    You must be logged in to view attached files.
    May 31, 2026 at 8:25 PM #54222

    Brendan
    Keymaster

    You’re returning Text. Try returning Number instead.

    There might be some precision or rounding issue.

    June 1, 2026 at 6:52 PM #54229

    Glen Forister
    Participant

    I changed the field to “number”. That didn’t change the values of DayofYr.
    See attached. The result goes off the rails quickly at the highlighted row.

    Attachments:
    You must be logged in to view attached files.
    June 2, 2026 at 11:49 AM #54231

    Daniel Leu
    Participant

    Seems like the proposed function runs into an issue with local time zones. Additionally, January 1st should return 1, shouldn’t it?

    Does following work better?

    function main(){
    
        function dayOfYear(date){
            const doy =  (Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) - Date.UTC(date.getFullYear(), 0, 0)) / 24 / 60 / 60 / 1000;
            return doy.toFixed(0);
        }
        
        const date = record.getFieldValue('fld-b095c0e1c1654c20a52530e22328eee8');
    
        if (date){
            return dayOfYear(date)
        }
    }
    
    main();
    

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    June 2, 2026 at 1:40 PM #54232

    Glen Forister
    Participant

    That worked.
    Thanks.

Viewing 16 reply threads

You must be logged in to reply to this topic.