Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the mathematical formula for converting days into weeks

I don't want decimal points like 65 days = 6.2weeks. I want 65 days = 6 weeks 1 day

I can't use any libraries (not homework)

like image 328
code511788465541441 Avatar asked Nov 28 '22 03:11

code511788465541441


2 Answers

Assuming Java (I don't know Javascript):

weeks    = days / 7;
days_out = days % 7;
like image 88
Oliver Charlesworth Avatar answered Dec 05 '22 18:12

Oliver Charlesworth


Simply use a modulus to get the amounts of days remaining then divide the rest by 7.

var daysLeft = days % 7;
var weeks = Math.floor(days / 7);

The code above works in both Java and JavaScript (remember, other than having "Java" in the name, Java and JavaScript are two different, unrelated languages). It might be more appropriate to declare the variables as an int in Java however.

like image 41
Andrew Moore Avatar answered Dec 05 '22 18:12

Andrew Moore