How to trim date, replace "-" with "/" and change format to dd/mm/yyyy

Jagadish Sanadi
Kilo Sage

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

1 REPLY 1

narendrareddy3
Tera Contributor

Thanks for sharing