The CreatorCon Call for Content is officially open! Get started here.

Allow only last day of month to be selected in date variable

Info-Remy
Giga Contributor

I have a requirement for a variable to display month and year. However, there is no OOB method for this. I have two options, and i want to know how feasible this is and how do i do it. the options are;

- Block out all dates except the last day of the month in calender or

- Throw an error message if any other day but the last day of the month is selected.

 

Any help is appreciated.

 

Thanks 

1 ACCEPTED SOLUTION

Thanks for your response. When i try your code, it sets the date as below.find_real_file.png

What could be the issue here?

View solution in original post

6 REPLIES 6

Sorry, my bad. The problem is with the date format. I'm using yyyy-MM-dd. Updated to take user's date format.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '' || oldValue == newValue) {
        return;
    }

    var curDate = getDateFromFormat(newValue, g_user_date_format);
    curDate = new Date(curDate);

    var lastDay = new Date(curDate.getFullYear(), curDate.getMonth() + 1, 0);
    var dateFormat = g_user_date_format;

    dateFormat = dateFormat.replace('yyyy', lastDay.getFullYear());
    dateFormat = dateFormat.replace('MM', zeroPad((lastDay.getMonth() + 1)));
    dateFormat = dateFormat.replace('dd', zeroPad(lastDay.getDate()));

    if (newValue != lastDay) {
        g_form.setValue('last_day_of_month', dateFormat);
    }

    function zeroPad(d) {
        return ('00' + d).slice(-2);
    }
}

Execution result using MM-dd-yyyy date format.

find_real_file.png

I need help similar to this.  

This is for a date variable on an sc_cat_item form.


The requirement is that the date selected must be in the future compared to the current date.
If the future date selected is not the first day of the month, it sets to the first day of the following month.  

(Just like how the Last day of month works above).

Examples:

1) If current date is 06/16/2022 and the date selected is 06/17/2022, then the date should autocorrect to 07/01/2022.

2) If current date is 06/16/2022 and the date selected is 12/02/2022, then the date should autocorrect to 01/01/2023.

 

Any help greatly appreciated.