Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Using Tap Forms 5 › ordinal day?
Tagged: Day of Year
- This topic has 16 replies, 3 voices, and was last updated 1 week, 5 days ago by
Glen Forister.
-
AuthorPosts
-
May 23, 2026 at 1:33 PM #54168
Glen ForisterParticipantI’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
BrendanKeymasterRemove the square brackets
[ ]from your formula.May 24, 2026 at 9:48 AM #54173
Glen ForisterParticipantThat 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 LeuParticipantWhat kind of type does the DMY calculation return?
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksMay 26, 2026 at 2:05 PM #54191
Glen ForisterParticipantWhat 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
BrendanKeymasterWhere 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 ForisterParticipantI 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
BrendanKeymasterHere’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 ForisterParticipantWell, 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 resultBoth 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
BrendanKeymasterThat’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 ForisterParticipantOMG, 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
BrendanKeymasterUse the Paste as Plain Text option under the Edit menu.
May 31, 2026 at 1:50 PM #54219
Glen ForisterParticipantI 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
BrendanKeymasterYou’re returning Text. Try returning Number instead.
There might be some precision or rounding issue.
June 1, 2026 at 6:52 PM #54229
Glen ForisterParticipantI 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 LeuParticipantSeems 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&tricksJune 2, 2026 at 1:40 PM #54232
Glen ForisterParticipantThat worked.
Thanks. -
AuthorPosts
You must be logged in to reply to this topic.