- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2018 03:24 PM
Not sure why I'm finding this so difficult but dates are my greatest weakness and greatly appreciate any help as I have searched endlessly and the glideDate's that I've tried have not worked.
I have an inbound script that I need to take a provided date in the body of the email notification and convert it to a different format and set it to just a string field. It is coming in as 10-Sep-2019 and needs to convert to 10/10/2019. The sender has no option to change their date format.
I know the script to apply it, without reformatting, would look like:
current.u_start_date = email.body.start_date
Thanks in advance!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2018 10:59 AM
Finally got it! I was doing my best to avoid what I used to have to do in the past like yours above. Thanks everyone.
var gd = new GlideDate();
gd.setDisplayValue(email.body.start_date, "dd-MMM-yyyy");
current.u_start_date = gd.getByFormat("MM/dd/yyyy");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2018 10:51 AM
You'll need to split the different parts of the date into different variables and then rearrange them to the desired format. I've done something similar in the past, although my final format is not the same as yours.
Here is my solution. You may need to change the final format to fit your needs, but hopefully this helps.
if (email.body.providedDate != undefined){
var providedDate = email.body.providedDate;
var myDate;
var providedDateString = providedDate.split("-");//format of providedDate should be YYYY-MMM-DD with MMM being letters for the month
var monthAlpha = providedDateString[1].split("-");//we want the second array in providedDate - this only grabs MMM
var monthInt;
switch (monthAlpha.toString()) {//convert the numerical value to the display value of the day
case 'JAN':
monthInt = "01";
break;
case 'FEB':
monthInt = "02";
break;
case 'MAR':
monthInt = "03";
break;
case 'APR':
monthInt = "04";
break;
case 'MAY':
monthInt = "05";
break;
case 'JUN':
monthInt = "06";
break;
case 'JUL':
monthInt = "07";
break;
case 'AUG':
monthInt = "08";
break;
case 'SEP':
monthInt = "09";
break;
case 'OCT':
monthInt = "10";
break;
case 'NOV':
monthInt = "11";
break;
case 'DEC':
monthInt = "12";
}
myDate = providedDate.replace(monthAlpha, monthInt);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2018 10:59 AM
Finally got it! I was doing my best to avoid what I used to have to do in the past like yours above. Thanks everyone.
var gd = new GlideDate();
gd.setDisplayValue(email.body.start_date, "dd-MMM-yyyy");
current.u_start_date = gd.getByFormat("MM/dd/yyyy");