How to make if compare number of data from java script

// Get the current date
const currentDate = new Date();

// Get the day, month, and year
const day = currentDate.getDate();
const month = currentDate.getMonth() + 1; // Month is zero-indexed, so add 1
const year = currentDate.getFullYear();

// Format the date as needed
const formattedDate = `${year}-${month < 10 ? '0' : ''}${month}-${day < 10 ? '0' : ''}${day}`;

// Print the formatted date
return(day);

The outcome i want is to use if compare today date
if 1-5 day choice1
if 12 day choice 2

Your JavaScript can be reduced to a single line:

return new Date().getDate();

However, that still won’t help you as the JavaScript column returns a string, which can’t be used in a numerical comparison.

A better approach here is to use a Math column with the following formula: Day(Now), where Now is the current date/time. This will return a number, which can be used directly in your if-then-else column.

1 Like

How to get last date of current month? or How many days in current month?
Also use in if condition.

This post might be helpful 📅 Guide: Mastering Dates & Times

3 Likes

Use this in a math column:

DAY(N-DAY(N)+15+30-DAY(N-DAY(N)+15+30))
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.