[Share script] How to get last week day.

36 views
Skip to first unread message

Allan Chen

unread,
Jun 3, 2015, 10:57:11 PM6/3/15
to adwords...@googlegroups.com
I think from today's date anti launch date approaches last Monday to Sunday, reference practice:

function main() {

  // get last week date (Mon - Sun)
  var now = new Date();
  var now_weekday = Utilities.formatDate(now, "u", "u")
  
  var sun_time = -now_weekday*60*60*24*1000;
  var mon_time = (-now_weekday-6)*60*60*24*1000;
  
  var now_time = Date.parse(now);
  var sunday_time = now_time + sun_time;
  var monday_time = now_time + mon_time;
  
  var sunday = now.setTime(sunday_time);
  var monday = now.setTime(monday_time);
  var endday = new Date(sunday); 
  var strday = new Date(monday); 
  var endfor = Utilities.formatDate(endday, "Md", "MMdd")
  var strfor = Utilities.formatDate(strday, "Md", "MMdd")
  
  Logger.log("Last_date is "+ strfor + "~" + endfor);

}

富鈞

unread,
Jun 4, 2015, 6:13:21 AM6/4/15
to adwords...@googlegroups.com
Thank's that I need.
Reply all
Reply to author
Forward
0 new messages