Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
   };
};
 
PREVIOUS NEXT
Tagged: #convert #days #days
ADD COMMENT
Topic
Name
9+8 =