Advertisement
dhniceday

Untitled

Nov 21st, 2022
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.71 KB | Software | 0 0
  1. <%*
  2. function pad(n) {
  3.   return n.toString().padStart(2, "0");
  4. }
  5. function fmtDate(d) {
  6.   var yyyy = d.getFullYear();
  7.   var mm = pad(d.getMonth() + 1);
  8.   var dd = pad(d.getDate());
  9.   var dArr = [ yyyy, mm, dd ];
  10.   return(dArr.join('-'));
  11. }
  12. function lastDay(a) {
  13.   if (typeof(a) === 'undefined' || a === '') {
  14.     var d = new Date();
  15.   } else {
  16.     var d = new Date(a + ' 12:00:00');
  17.     if (d.toString() === 'Invalid Date') {
  18.       console.log('invalid date');
  19.       return
  20.     }
  21.   }
  22.   var lastDay = new Date(d.getFullYear(),d.getMonth()+1,0);
  23.   lastDate = fmtDate(lastDay)
  24.   lastDay = lastDay.getDate()
  25.   return lastDate // change to "lastDay" to output day only
  26. } %><% lastDay(tp.file.selection())%>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement