How to convert date format "Day, Month Date, Year HH:SS AM to date/time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 02:04 PM
Hello all,
I have a requirement to read Sent: information in email body and convert it into date time value.
For example, Below is the value that comes in email body.
Sent: Friday, August 18, 2017 8:00 AM
I need to convert above info into date/time value i.e, MM-DD-YYYY HH:MM:SS format.
Appreciate any help with this.
Thanks
Mahduri

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 02:07 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 04:53 PM
Hi Madhu,
Please check if this helps, I have tried with seconds also, if you don't get seconds in time then i think you can hard code to 00.
var sentdate = 'Friday, August 18, 2017 5:00:00 PM';
var hrs = 12, time;
var splitdate = sentdate.split(',');
var Day = splitdate[0];
var Date1 = splitdate[1] + '' + splitdate[2];
var splitdate1 = Date1.split(' ');
if(splitdate1[1] == 'January')
var mon = '01';
if(splitdate1[1] == 'February')
var mon = '02';
if(splitdate1[1] == 'March')
var mon = '03';
if(splitdate1[1] == 'April')
var mon = '04';
if(splitdate1[1] == 'May')
var mon = '05';
if(splitdate1[1] == 'June')
var mon = '06';
if(splitdate1[1] == 'July')
var mon = '07';
if(splitdate1[1] == 'August')
var mon = '08';
if(splitdate1[1] == 'September')
var mon = '09';
if(splitdate1[1] == 'October')
var mon = '10';
if(splitdate1[1] == 'November')
var mon = '11';
if(splitdate1[1] == 'December')
var mon = '12';
var splittime = splitdate1[4].split(':');
if(splitdate1[5] == 'PM'&& splittime[0] < parseInt(hrs))
time = parseInt(splittime[0]) + parseInt(hrs);
else
time = splittime[0];
var formdate = mon + '-' + splitdate1[2] + '-' + splitdate1[3] + ' ' + time + ':' + splittime[1] + ':' + splittime[2];
gs.print(formdate);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 12:51 PM
Hi Shishir,
Thanks for the reply. The scripts is working fine. However i want to validate if email.body.sent value is same as the format Friday, August 18, 2017 5:00:00 PM.
trying to check with regex if that matches then only convert the sent info to date. Otherwise ignore. Can you help on this?
Regards
Madhuri

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 09:15 PM
That's little tricky and requires to develop function based upon your date format, would like to suggest to go below links which may help you to generate the script.
http://www.w3resource.com/javascript/form/javascript-date-validation.php
validation - How to validate date with format "mm/dd/yyyy" in JavaScript? - Stack Overflow