Link to home
Start Free TrialLog in
Avatar of John S.
John S.Flag for United States of America

asked on

Count Number of Weeks until a date

I need a way to display the number of weeks and days until a certain date ( in my case, August 30th ) to display in a DIV on out site:



Is there a Javascript solution to figure this out?

Thank you for looking.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John S.

ASKER

Bill can you help me set the start date to right now? Then this will be perfect!
Avatar of Bill Prew
Bill Prew

moment() represents the current time.  I updated the example here:  https://jsfiddle.net/pydhj4ev/1/


»bp
Avatar of John S.

ASKER

this did it, thanks, Bill

[code]
var a = moment();
var b = moment('30/09/2018', 'DD/MM/YYYY');
var days = b.diff(a, 'days');
var weeks = b.diff(a, 'weeks');
document.getElementById("days").innerHTML = days
document.getElementById("weeks").innerHTML = weeks
[/code]

Wow what a nice library that is huh!
Yes, it can be very helpful, and there is a lot to it.

(if you posted your last comment from a mobile device that is what the [code] formatting didn't work, it's a known problem currently...)


»bp