Getting values from array one by one and writing some text according to array length to them javascript -
i have problem getting results functon, estimated # 11 years(let), , 10 days(dnů) or if there in no years output should 10 days, in case of years, months , days, should 10 years, 3 months , 4 days...here code
function getage(date_1, date_2) { var date2_utc = new date(date.utc(date_2.getutcfullyear(), date_2.getutcmonth(), date_2.getutcdate())); var date1_utc = new date(date.utc(date_1.getutcfullyear(), date_1.getutcmonth(), date_1.getutcdate())); var yappendix, mappendix, dappendix; var days = date2_utc.getdate() - date1_utc.getdate(); if (days < 0) { date2_utc.setmonth(date2_utc.getmonth() - 1); days += daysinmonth(date2_utc); } var months = date2_utc.getmonth() - date1_utc.getmonth(); if (months < 0) { date2_utc.setfullyear(date2_utc.getfullyear() - 1); months += 12; } var years = date2_utc.getfullyear() - date1_utc.getfullyear(); if (years > 5) yappendix = " let"; else if(years <= 4 && years >= 2) yappendix = " roky"; else yappendix = " rok"; if (months > 5) mappendix = " měsíců"; else if(months <= 4 && months >= 2) mappendix = " měsíce"; else mappendix = " měsíc"; if (days > 5) dappendix = " dnů"; else if(days <= 4 && days >= 2) dappendix = " dny"; else dappendix = " den"; var array = []; var echo; if(years == 0){} else array.contact = years + yappendix; if(months == 0){} else array.contact = months + mappendix; if(days == 0){} else array.contact = days + dappendix; if(array.length = 1) echo = array[0]; else if(array.length = 2) echo = array[0] + " " + array[1]; else echo = array[0]+ ", " +array[1] + " " + array[2]; console.log(array); return echo; } function daysinmonth(date2_utc) { var monthstart = new date(date2_utc.getfullyear(), date2_utc.getmonth(), 1); var monthend = new date(date2_utc.getfullyear(), date2_utc.getmonth() + 1, 1); var monthlength = (monthend - monthstart) / (1000 * 60 * 60 * 24); return monthlength; }
thanks help
Comments
Post a Comment