Skip to content

Instantly share code, notes, and snippets.

@postman31
Last active April 2, 2018 14:25
Show Gist options
  • Save postman31/48548559767352e4e5b016d69be3a026 to your computer and use it in GitHub Desktop.
Save postman31/48548559767352e4e5b016d69be3a026 to your computer and use it in GitHub Desktop.
simple function to check whether the campaign is ended
/**
* 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