Last active
April 2, 2018 14:25
-
-
Save postman31/48548559767352e4e5b016d69be3a026 to your computer and use it in GitHub Desktop.
simple function to check whether the campaign is ended
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks if campaig has and end date later then today | |
* | |
* @return {string} 'ENDED' if true 'IN PROGRESS' otherwise. | |
* example usage: | |
* while (campaignIterator.hasNext()) { | |
* var campaign = campaignIterator.next(); | |
* if (endedStatus(campaign) == 'ENDED') continue | |
* } | |
*/ | |
function endedStatus(campaign) { | |
var status = 'IN PROGRESS' | |
var endDate = campaign.getEndDate() | |
if (!endDate) { | |
return status | |
} else { | |
var now = new Date() | |
var timeZone = AdWordsApp.currentAccount().getTimeZone(); | |
var year = Utilities.formatDate(now, timeZone, 'yyyy') | |
var month = Utilities.formatDate(now, timeZone, 'MM') | |
var day = Utilities.formatDate(now, timeZone, 'dd') | |
if (endDate.year < year) { | |
status = 'ENDED' | |
} else if (endDate.year == year && endDate.month < month) { | |
status = 'ENDED' | |
} else if (endDate.year == year && endDate.month == month && endDate.day < (day)) { | |
status = 'ENDED' | |
} | |
return status | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment