I'm really struggling to do a clean, efficient way of showing yearweek for Sunday to Monday
e.g.: 201624 201625 201626 201627 201628
Is there an efficient way to do so in Google Scripts or Javascript without using a library?
Thanks!
I'm really struggling to do a clean, efficient way of showing yearweek for Sunday to Monday
e.g.: 201624 201625 201626 201627 201628
Is there an efficient way to do so in Google Scripts or Javascript without using a library?
Thanks!
Found a solution! :
var yearMonth = parseInt(Utilities.formatDate(new Date(), SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone(), "yyyyww")).toFixed(0);
It was provided by user: Balu Ertl at Get week of year in JavaScript like in PHP
I would use Moment.js. Documentation for the use can be found here for the format you are looking for http://momentjs.com/docs/#/displaying/.
To have it work with google script you will need to first add it to the libraries using MHMchiX6c1bwSqGM1PZiW_PxhMjh3Sh48
, then you need to load it in using something like var moment = Moment.load()
.
From here you can get the month and year already formatted into your requested format.
var date = getDate();
var wwyy = moment(date).format('wo, YY');
My appologies, my format wasn't exactly as you wanted it to be. To answer in the format you are looking for:
var date = new Date();
var yyyyww = moment(date).format('YYYY ww');