Hubro Hubro - 1 month ago 15
Javascript Question

How do I convert Google Scripts date range strings like "LAST_MONTH" to actual dates?

Several functions in Google Scripts for Adwords supports the following date range strings:


TODAY, YESTERDAY, LAST_7_DAYS, THIS_WEEK_SUN_TODAY, LAST_WEEK, LAST_14_DAYS, LAST_30_DAYS, LAST_BUSINESS_WEEK, LAST_WEEK_SUN_SAT, THIS_MONTH, LAST_MONTH, ALL_TIME


One would think that the functions you pass the strings to were able to convert those strings to a start and end date. For instance, LAST_MONTH would be converted to start date 2013-02-01 and end date 2013-02-28, and TODAY would be converted to start- and end date 2013-03-01.

Does Google Scripts also provide a way for users to parse those strings into a start and end date?

Answer

I asked this same question on Google Groups (here is the answer.). To summarize, there is no public method for achieving this in Google Scripts, and a custom solution has to be deployed. Since I'm exporting the Adwords data to a personal database anyway I'll be solving this using PHP, so I won't be posting a solution here.