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

Best way to have a list view of dates that are the beginning pay periods

Adam Peterson
Kilo Sage

I am in need of a way to have them select a date but they are only allowed to select the first day of a pay period. So pretty much I need to display every other Sunday. 

Should I use a date field? Should I populate a select box? What's the best way to approach this?

 

Thanks!

1 ACCEPTED SOLUTION

Ok @Adam Peterson 

 

Got it ! Below 👇 script should work 

 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue === '') return;

 

    var selectedDate = new Date(newValue);

    var day = selectedDate.getDay(); // 0 = Sunday

 

    if (day !== 0) {

        g_form.showFieldMsg('your_date_field', 'Please select a Sunday.', 'error');

        g_form.setValue('your_date_field', '');

        return;

    }

 

    // Base Sunday: April 6, 2025

    var baseSunday = new Date('2025-04-06');

    var diffTime = selectedDate.getTime() - baseSunday.getTime();

    var diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));

 

    if (diffDays % 14 !== 0 || diffDays < 0) {

        g_form.showFieldMsg('your_date_field', 'Please select an alternate Sunday starting from April 6, 2025.', 'error');

        g_form.setValue('your_date_field', '');

    } else {

        g_form.hideFieldMsg('your_date_field', true);

    }

}

 

Please change the field names accordingly. 

 

I tried with - 2025-04-13 - didn't accept 

2025-04-27 - didn't accept 

2025-05-18 - accepted. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

View solution in original post

7 REPLIES 7

We could start with 4/6/25 and then every two weeks after that.

4/6/25
4/20/25
5/4/25
5/18/25
etc

Ok @Adam Peterson 

 

Got it ! Below 👇 script should work 

 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue === '') return;

 

    var selectedDate = new Date(newValue);

    var day = selectedDate.getDay(); // 0 = Sunday

 

    if (day !== 0) {

        g_form.showFieldMsg('your_date_field', 'Please select a Sunday.', 'error');

        g_form.setValue('your_date_field', '');

        return;

    }

 

    // Base Sunday: April 6, 2025

    var baseSunday = new Date('2025-04-06');

    var diffTime = selectedDate.getTime() - baseSunday.getTime();

    var diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));

 

    if (diffDays % 14 !== 0 || diffDays < 0) {

        g_form.showFieldMsg('your_date_field', 'Please select an alternate Sunday starting from April 6, 2025.', 'error');

        g_form.setValue('your_date_field', '');

    } else {

        g_form.hideFieldMsg('your_date_field', true);

    }

}

 

Please change the field names accordingly. 

 

I tried with - 2025-04-13 - didn't accept 

2025-04-27 - didn't accept 

2025-05-18 - accepted. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

I like it! Thanks!