SN_Learn
Kilo Patron
Kilo Patron

Use Case:

 

There are 2 fields on a form say 'Start Date' and 'End Date'. Now, if we want to set the start date field as the starting of month and 'End Date' field as the end date of month but it will only select the end date of the respective month which is selected in the 'End Date' field.

 

The below sample script will help to get the start of month and end date of the month if any DD/MM/YYYY is provided.

 

 

 

 

var startDate = '20/05/2024';
var endDate = '25/05/2024';

var date = startDate;
var dateParts = date.split('/');
var month = dateParts[1];
var year = dateParts[2];
var startDate = '01/' + month + '/' + year;
var endDate = new Date(year, month, 0).getDate() + '/' + month + '/' + year;

gs.log(startDate);
gs.log(endDate);

}
Output :

*** Script: 01/05/2024
*** Script: 31/05/2024

 

 

 

 

Mark it as helpful and solution proposed if it serves your purpose.