New online calculator functions
Good afternoon.
We continue to improve our constructor of web forms and calculators, and add more and more new functions. Today we want to talk about new mathematical functions that can now be used in their formulas for calculations, and there are a lot of them.
At this point, you can use these functions in your calculations:
round() | Returns the number rounded to the nearest integer |
ceil() | Rounds the number to the nearest whole number |
floor() | Rounds the number to the nearest integer |
roundUp() | Rounds the number to the nearest multiple of the given number. |
min() | Returns the smallest of several numbers |
max() | Returns the largest of several numbers |
medium() | Returns the average of several numbers |
today() | Returns the number of seconds from the current date |
datetime() | Returns the number of seconds from the current date and time |
strlen() | Returns the number of characters in the string |
pow() | Expanding a number |
ln() | The natural logarithm |
lg() | Decimal logarithm |
log() | The logarithm of a number on any base |
sin() | Sine of the angle in radians |
cos() | The cosine of the angle in radians |
tan() | Tangent angle in radians |
ctg() | The ctangent of angle in radians |
mod() | The remainder of the division of two numbers |
countYears() | Returns the number of years from the difference of two dates |
countMonths() | returns the number of months from the difference of two dates |
countDays() | Returns the number of days of the difference of two dates |
year() | Extracts year from the date |
month() | Extracts month from the date |
day() | Extracts day from the date |
countRemainingDays() | Returns the number of days remaining from the difference of two dates |
countRemainingMonths() | Returns the number of remaining months from the difference of two dates |
date() | Returns the number of seconds from the date of the passed parameters (year, month, day) |
dateValue() | Returns the total of all digits of the date |
You are already familiar with some of the functions from our past articles. Today we wanted to elaborate on these functions: roundUp(), mod(), countYears(), countMonths(), countDays(), year(), month(), day(), countRemainingDays(), countRemainingMonths(), date(), dateValue().
Most of these functions add new features when working with the date. But about everything in order.
dateValue(date)
This function returns the total number of all digits of the date. This is usually used in numerology to count the number of the date of birth. Example:
dateValue('1985-08-20') = 1 + 9 + 8 + 5 + 0 + 8 + 2 + 0 = 33 = 3 + 3 = 6
roundUp(a, b)
This function rounds the number a to the nearest larger multiple of the number b. Example:
roundUp(4, 3) = 6; roundUp(5, 3) = 6; roundUp(7, 3) = 9.
roundUp(a, b)
This function rounds the number a to the nearest larger multiple of the number b. Example:
roundUp(4, 3) = 6; roundUp(5, 3) = 6; roundUp(7, 3) = 9.
mod(a, b)
This function returns the remainder of the division of the number a by the number b. Example:
mod(10, 3) = 1; mod(10, 2) = 0; mod(35, 4) = 3.
If the number b = 1, and the number a is fractional, then the function mod() returns the fractional part of the number a:
mod(3.45, 1) = 0.45.
countYears(date1, date2)
This function returns the number of full years from the difference of two dates: date1 and date2. Example:
countYears('2022-01-25', '2020-01-25') = 2; countYears('2022-01-25', '2020-01-26') = 1; //(one day is missing for a full two years) countYears('2022-01-25', '2019-06-26') = 2;
countMonths(date1, date2)
This function returns the number of full months from the difference of two dates: date1 and date2. Example:
countMonths('2022-01-25', '2021-11-25') = 2; countMonths('2022-01-25', '2019-06-26') = 30.
countDays(date1, date2)
This function returns the number of days from the difference of two dates: date1 and date2. Example:
countDays('2022-01-25', '2021-12-25') = 31; countDays('2022-01-25', '2019-06-26') = 944.
year(date)
This function extracts the year from the date. Example:
year('2022-01-25') = 2022; year('1985-11-03') = 1985.
month(date)
This function extracts the month from the date. Example:
month('2022-01-25') = 1; month('1985-11-03') = 11;
day(date)
This function extracts the day from the date. Example:
day('2022-01-25') = 25; day('1985-11-03') = 3;
countRemainingDays(date1, date2)
This function returns the number of remaining days from the difference of two dates, minus full years and months. This function is very convenient to use when calculating the user's age by date of birth. Example:
countRemainingDays('2022-01-25','1985-08-20') = 5; countRemainingDays('2022-01-25','1985-08-25') = 0; countRemainingDays('2022-01-25','1985-08-26') = 30;
countRemainingMonths(date1, date2)
This function returns the number of remaining months from the difference of two dates, minus full years and days. This function is very convenient to use when calculating the user's age by date of birth. Example:
countRemainingMonths('2022-01-25','1985-08-20') = 5; countRemainingMonths('2022-01-25','1985-01-20') = 0; countRemainingMonths('2022-01-25','1985-04-24') = 9; countRemainingMonths('2022-01-25','1985-04-26') = 8;
date(year, month, day)
This function creates the date of the passed parameters (year, month, day), which can be used in other functions and calculations (any date is converted to label unix timestamp - the number of seconds since midnight of 1 January 1970).
Let's look at some real-life examples.
How many days are left until the New Year?
As an example, let's calculate how many days are left until the New Year. The following functions will help us with this: Counts(date1, date2), today() and year().
As you remember, the function Counts(date1, date2) returns the number of days from the difference of two dates. In our case:
- date1 - New Year's date
- date2 - current date
In the simplest case, our formula will look like this:
countDays(date(2022,12,31), today())
But this is not very convenient, since the year 2022 is registered manually and it will need to be changed to 2023 in 1 year so that everything is correctly counted. But here the year() function comes to our aid, which extracts the year from the date. Using this function we can rewrite our formula as follows:
countDays(date(year(today()),12,31), today())
That is, using the record year(today()) - we dynamically get the year from the current date. In the same way, you can combine all other functions.
How many days are left until the birthday?
Let's look at another example: a user enters his date of birth in the form and we need to calculate how many days are left before his DR. All the same functions that we considered in the previous example will help us in this, namely, Counts(date1, date2) returns the number of days from the difference of two dates. In our case:
- date1 - here we need to form a date where the day and month will be the one that the user entered into the form, and the year must be used the current one. For example, if the date of birth is 1985-08-20, then we need to get this date: 2022-08-20 and it is up to this date that we need to count the number of remaining days.
- date2 - current date
So, our formula might look like this:
Counts(date(year(today()), month(field 1), day(field 1)), today())
Where field #1 is the field from the form where the user enters his date of birth.
That's all for today. And what functions do you lack for your calculators?