- In the Misc Settings, set a value that is greater than or equal to 1 for Number of Decimal Places to Round.
Setting the Significant Digits of Numbers and the Rounding Method
- Place the following fields in the form of the app settings and set field names, field codes, and formulas for each.
<Example 1>
- Date Field
・Field Name/Field Code: Date
- Text Field
・Field Name/Field Code: Day
・Formula:
IF( ( ( (Date / 60 / 60 / 24) - 0) / 7 ) - ROUNDUP(( ( (Date / 60 / 60 / 24) - 0) / 7 ) , 0) = 0 , "Thursday",
IF( ( ( (Date / 60 / 60 / 24) - 1) / 7 ) - ROUNDUP(( ( (Date / 60 / 60 / 24) - 1) / 7 ) , 0) = 0 , "Friday",
IF( ( ( (Date / 60 / 60 / 24) - 2) / 7 ) - ROUNDUP(( ( (Date / 60 / 60 / 24) - 2) / 7 ) , 0) = 0 , "Saturday",
IF( ( ( (Date / 60 / 60 / 24) - 3) / 7 ) - ROUNDUP(( ( (Date / 60 / 60 / 24) - 3) / 7 ) , 0) = 0 , "Sunday",
IF( ( ( (Date / 60 / 60 / 24) - 4) / 7 ) - ROUNDUP(( ( (Date / 60 / 60 / 24) - 4) / 7 ) , 0) = 0 , "Monday",
IF( ( ( (Date / 60 / 60 / 24) - 5) / 7 ) - ROUNDUP(( ( (Date / 60 / 60 / 24) - 5) / 7 ) , 0) = 0 , "Tuesday",
IF( ( ( (Date / 60 / 60 / 24) - 6) / 7 ) - ROUNDUP(( ( (Date / 60 / 60 / 24) - 6) / 7 ) , 0) = 0 , "Wednesday","N/A"
)
)
)
)
)
)
)
<Example 2>
- Date and time Field
・Field Name/Field Code:Date_and_Time
- Text Field
・Field Name/Field Code: Day
・Formula:IF( ( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24) ) - 0) / 7 ) - ROUNDUP(( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24)) - 0) / 7 ) , 0) = 0 , "Thursday",
IF( ( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24) ) - 1) / 7 ) - ROUNDUP(( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24)) - 1) / 7 ) , 0) = 0 , "Friday",
IF( ( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24) ) - 2) / 7 ) - ROUNDUP(( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24)) - 2) / 7 ) , 0) = 0 , "Saturday",
IF( ( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24) ) - 3) / 7 ) - ROUNDUP(( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24)) - 3) / 7 ) , 0) = 0 , "Sunday",
IF( ( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24) ) - 4) / 7 ) - ROUNDUP(( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24)) - 4) / 7 ) , 0) = 0 , "Monday",
IF( ( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24) ) - 5) / 7 ) - ROUNDUP(( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24)) - 5) / 7 ) , 0) = 0 , "Tuesday",
IF( ( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24) ) - 6) / 7 ) - ROUNDUP(( ( (ROUNDDOWN((Date_and_Time+(60 * 60 * 9))/ 60 / 60 / 24)) - 6) / 7 ) , 0) = 0 , "Wednesday","N/A"
)
)
)
)
)
)
)
Caution
If you use the formula shown in the "Formula to use when a 'Date and time' field is placed on the app form" section, note the following:
- Japan Standard Time (JST) is used for the time zone.
Since JST is nine hours ahead of Unix time, the "Date and time" field is calculated based on Unix time plus nine hours (in seconds). If you want to use the formula in a different time zone, change the "9" to the number that matches your time zone. - If you enter a time before January 1, 1970 in the "Date and time" field, the value will not be calculated correctly.
For details, refer to the following page.
Calculation of Date, Time, and Date and Time
○Explanation of the Formula
Formulas in kintone treat the values in "Date" and "Date and time" fields as Unix time, which is the number of seconds elapsed since 1970-1-1 00:00 UTC (Coordinated Universal Time).
How values in "Date", "Time", and "Date and time" fields are treated
In the formulas on this page, the date value entered in a field is converted to the number of days elapsed since the Unix epoch and then calculated. The day of the week that corresponds to a date value is displayed using the concept of dividing the number of days elapsed since the Unix epoch by 7 (the number of days in a week), and then determining the day of the week based on the remainder.
<Examples>
- If you enter April 1, 2021:
The number of days that have elapsed since Thursday, January 1, 1970 is 18,718.
18,718 divided by 7 is 2,674 with remainder 0.
This means that April 1, 2021 is exactly 2,674 weeks after Thursday, January 1, 1970. Because the date is 0 days after Thursday, the day of the week must be Thursday.
In other words, the day of the week is always Thursday when the number of days that have elapsed since January 1, 1970 is divided by 7 and the remainder is 0.
- If you enter April 2, 2021:
The number of days that have elapsed since Thursday, January 1, 1970 is 18,719.
18,719 divided by 7 is 2,674 with remainder 1.
This means that April 2, 2021 is 2,674 weeks and one day after Thursday, January 1, 1970. Because the date is one day after Thursday, the day of the week must be Friday.
In other words, the day of the week is always Friday when the number of days that have elapsed since January 1, 1970 is divided by 7 and the remainder is 1.
In the examples above, the remainder returned after dividing the number of days elapsed since the Unix epoch by 7 is used to find the day of the week as follows.
A) When the number of elapsed days is divided by 7 and it returns remainder 0: Thursday
B) When the number of elapsed days is divided by 7 and it returns remainder 1: Friday
C) When the number of elapsed days is divided by 7 and it returns remainder 2: Saturday
D) When the number of elapsed days is divided by 7 and it returns remainder 3: Sunday
E) When the number of elapsed days is divided by 7 and it returns remainder 4: Monday
F) When the number of elapsed days is divided by 7 and it returns remainder 5: Tuesday
G) When the number of elapsed days is divided by 7 and it returns remainder 6: Wednesday
However, the calculation features of kintone cannot be used to find remainders.
For this reason, instead of determining the day of the week directly from the remainder, the day of the week is determined by subtracting the remainder value from the number of days elapsed and calculating a value that is evenly divisible by 7.
To calculate a value that is evenly divisible by 7, the remainder value is returned as a decimal number, which is then rounded up to the nearest whole number using the ROUNDUP function.
When the difference of subtracting [(the number of elapsed days - X) divided by 7] from [the quotient of dividing (the number of elapsed days - X) by 7 rounded to a whole number using the ROUNDUP function] is 0, it is determined that a value is evenly divisible by 7 (or, in other words, has a remainder of 0). The day of the week is then determined as follows.
A) When the number of elapsed days minus 0 is divided by 7 and it returns remainder 0: Thursday
B) When the number of elapsed days minus 1 is divided by 7 and it returns remainder 0: Friday
C) When the number of elapsed days minus 2 is divided by 7 and it returns remainder 0: Saturday
D) When the number of elapsed days minus 3 is divided by 7 and it returns remainder 0: Sunday
E) When the number of elapsed days minus 4 is divided by 7 and it returns remainder 0: Monday
F) When the number of elapsed days minus 5 is divided by 7 and it returns remainder 0: Tuesday
G) When the number of elapsed days minus 6 is divided by 7 and it returns remainder 0: Wednesday
Note
- When a "Date and time" field is placed on the app form
Since "Date and time" fields include a time value, the time portion must be processed in the calculation based on the number of days. When using the time value, the calculated value of elapsed days will contain a decimal value. However, the number of elapsed days must be handled in integer format in the above formula example. Due to this reason, the ROUNDDOWN function is used to round down the decimal value.
ROUND, ROUNDUP, and ROUNDDOWN Functions: Round Off, Round Up, and Round Down Numeric Values