date displays time in email body

79 views
Skip to first unread message

Melissa Varazlic

unread,
Oct 20, 2023, 4:20:30 PM10/20/23
to Google Apps Script Community
I am creating a script to  email vendors when their insurance is expiring.  The script runs but when I post the expiration date in the email body it has the full date and time.  I just want it to have Wed November 15, 2023 instead of: Wed Nov 15 2023 00:00:00 GMT-0600 (Central Standard Time).  When I try to do this:

var formateddate= new Date(insuranceExpirationDate);
formateddate= Utilities.formatDate(formateddate,'EEE MMM dd yyyy');
I get this error:
The parameters ((class).String) don't match the method signature for Utilities.formatDate

I am not good at this so it may be something crazy simple that is wrong.  I am using the insuranceExpirationDate variable for some calculations so I was hoping to leave it alone and create a new variable (formateddate).  I assume that it is pulling insuranceExpirationDate as a string but I thought the new Date command would change it to a date.  Any help is greatly appreciated.

Thanks!!
Melissa

Ed Sambuco

unread,
Oct 20, 2023, 8:01:57 PM10/20/23
to google-apps-sc...@googlegroups.com
insuranceExpirationDate should be a string.   is it?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/2ff9fbdb-e0a7-4238-aafb-8c8d9de3d493n%40googlegroups.com.

Melissa Varazlic

unread,
Oct 23, 2023, 11:12:36 AM10/23/23
to Google Apps Script Community
It seems like it is a string.  At least that is how I read the error.

Melissa Varazlic

unread,
Oct 24, 2023, 3:21:25 PM10/24/23
to Google Apps Script Community
This is how I fixed it:
var date= new Date(insuranceExpirationDate);
var formattedDate= date.toLocaleDateString('en-US');
Reply all
Reply to author
Forward
0 new messages