SN_Learn
Kilo Patron
Options
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
03-25-2024
04:58 AM
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.