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.
John S.Web DeveloperAsked:
Who is Participating?
 
Bill PrewCommented:
How about using Moment.js, then this becomes quite easy, as in: https://jsfiddle.net/pydhj4ev/


»bp
1
 
John S.Web DeveloperAuthor Commented:
Bill can you help me set the start date to right now? Then this will be perfect!
0
 
Bill PrewCommented:
moment() represents the current time.  I updated the example here:  https://jsfiddle.net/pydhj4ev/1/


»bp
1
 
John S.Web DeveloperAuthor Commented:
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!
0
 
Bill PrewCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.