Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert days into year, Month, days

//Method 1
function getFormatedStringFromDays(numberOfDays) {
    var years = Math.floor(numberOfDays / 365);
    var months = Math.floor(numberOfDays % 365 / 30);
    var days = Math.floor(numberOfDays % 365 % 30);

    return [years, months, days].join(':');
}

//Method 2
const calculateTimimg = d => {
   let months = 0, years = 0, days = 0;
   while(d){
      if(d >= 365){
         years++;
         d -= 365;
      }else if(d >= 30){
         months++;
         d -= 30;
      }else{
         days++;
         d--;
      }
   };
   return {
      years, months, days
   };
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: ajax code 
Javascript :: how to convert node list to array in javascript 
Javascript :: datatables filter with math functions 
Javascript :: how to check all values of an array are equal or not in javascript 
Javascript :: how to make @click in router-link vuejs 
Javascript :: make multiple function calls at the same time js async 
Javascript :: bulk create in sequelize 
Javascript :: Min-Stack Optimized Solution Via JS 
Javascript :: simple ajax request 
Javascript :: how to read all files in a folder in node js 
Javascript :: input type search clear event 
Javascript :: react-router-dom redirect 
Javascript :: how to slice/trim/remove last character in string 
Javascript :: how to add data to file json in python 
Javascript :: days difference in moment js 
Javascript :: javascript null true or false 
Javascript :: reset function javascript 
Javascript :: use eslint in vscode 
Javascript :: link stylesheet in javascript 
Javascript :: Loop over all keys in the local storage 
Javascript :: remove line break javascript 
Javascript :: ajax syntax in javascript 
Javascript :: javascript get parent by tag 
Javascript :: df.saveto json 
Javascript :: js convert date to timestamp 
Javascript :: what indexof in javascript 
Javascript :: how to read breakline in html 
Javascript :: finding an element ina na array in js 
Javascript :: expo custom fonts 
Javascript :: javascript kill ajax request 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =