Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript get current week number

function weekNumber(date = new Date())
{
  var firstJanuary = new Date(date.getFullYear(), 0, 1);
  var dayNr = Math.ceil((date - firstJanuary) / (24 * 60 * 60 * 1000));
  var weekNr = Math.ceil((dayNr + firstJanuary.getDay()) / 7);
  return weekNr;
}
Comment

javascript get date of the week

//Grab day of the week from local computer
let date = new Date();
let dayOfWeekNumber = date.getDay();
let nameOfDay;
let quote;

switch(dayOfWeekNumber){
    case 0: 
        nameOfDay = 'Sunday';
        quote = 'Time to chillax!';
        break;
    case 1:
        nameOfDay = 'Monday';
        quote = 'Monday morning blues!';
        break;
    case 2:
        nameOfDay = 'Tuesday';
        quote = 'Taco Time!';
        break;
    case 3:
        nameOfDay = 'Wednesday';
        quote = 'Two more days to the weekend.';
        break;
    case 4:
        nameOfDay = 'Thursday';
        quote = 'The weekend is almost here...';
        break;
    case 5:
        nameOfDay = 'Friday';
        quote = 'Weekend is here!';
        break;
    case 6:
        nameOfDay = 'Saturday';
        quote = 'Time to party!';
        break;

}
//Display the day of the week
let weekdayDiv = document.getElementById('weekday');
weekdayDiv.innerHTML = `${nameOfDay}`;

//Display quote
let quoteDiv = document.getElementById('phrase');
quoteDiv.innerHTML = `${quote}`


Comment

PREVIOUS NEXT
Code Example
Javascript :: moment check days of difference between days 
Javascript :: disable server side rendering next.js 
Javascript :: how to create a .js file in windows command prompt code 
Javascript :: new date with date + 1 
Javascript :: javascript log Time from Date 
Javascript :: jquery Audio Play on button click 
Javascript :: get value from another textinput and set is to another using jquery 
Javascript :: H. Nazmul Hassan 
Javascript :: jquery data-toggle modal and tooltip 
Javascript :: document.queryselector vs document.getelementbyid 
Javascript :: js string to date 
Javascript :: javascript json string 
Javascript :: how to access xpath in js 
Javascript :: sorting number with coma datatable 
Javascript :: get filename from url js 
Javascript :: vue watch deep property 
Javascript :: fs move file 
Javascript :: material ui datepicker remove error 
Javascript :: javascript object equals 
Javascript :: adonis count with where 
Javascript :: javascript array value dom 
Javascript :: redirect link javascript 
Javascript :: get first two letter of an array javascript 
Javascript :: browserrouter react 
Javascript :: console redux state shows proxy 
Javascript :: Javascript prime number check 
Javascript :: how to check if connected to internet js 
Javascript :: react overflow scroll 
Javascript :: how to add another schema id on mongodb 
Javascript :: js create element from string 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =