How to trim date, replace "-" with "/" and change format to dd/mm/yyyy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 06:24 AM - edited 09-12-2023 06:25 AM
Please try this code to trim hh:mm:ss , replace "-" with "/" and change format to dd/mm/yyyy
var date1 = "2023-09-12 11:22:08";
var dateParts1 = date.split(' '); // Split the string into date and time parts
var storyPlannedStartDate= dateParts1[0];
storyPlannedStartDate = storyPlannedStartDate.replace(/-/g, '/');// Select the date part
var format2 = storyPlannedStartDate.split('/'); //change format
var formattedPlannedStartDateOnly = format2[2] + '/' + format2[1] + '/' + format2[0];//format changing line
output = formattedPlannedStartDateOnly;
gs.log(output); 12/09/2023
Please mark as useful if this helped you
- 293 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 06:25 AM
Thanks for sharing