Jquery Countup Until Next Monday and total Mondays from defined date until todays date

0 votes

I'm trying to code a count up that show how many MONDAYS we had from a specific date.

For example since 10/01/2012 we had 4 mondays until today October 25.

This first step I could achieve with some coding searching from some places and adapting it to my needs.

Now the tricky part for me is to make a way to show a count up that shows a percentage of how much from now to the next month is remaining to increase another monday to the main counter.

For example, from 10/01/2012 we had 4 mondays until now, but October 25 is Thursday so how could I do a count up that shows the time increasing with the value that is remaining to achieve next monday?

I tried to put as a count up like using days, hours, minutes and seconds so everytime it runs it starts from today with the value counting up to the next monday so week by week we would have a number like this in the counter: 6days 23hours 59minutes 59seconds and then add a new number to the number of mondays so we achieved a new monday after the 6 days, but of course if I visit the page running the code in the middle I will already have the counter with the value added on it and counting each second live.

Could someone help? If you know a better way to achieve the same goal it is perfectly ok.

To summarize what I want to achieve is a counter that says how many mondays have passed and how much time is left to the next monday and counting up live. It has to keep going for ever not to stop on the next monday, after achieving the following monday it keeps going until the next.

Questions are welcome!

<pre><code>


// This Code Counts how many mondays from a specified date to the actual date.
// Create a new date variable
var d = new Date();
var month = d.getMonth() + 1;
var day = d.getDate();

// Get the actual date and store on a variable
var actualDate = d.getFullYear() + '/' + (('' + month).length < 2 ? '0' : '') + month + '/' + (('' + day).length < 2 ? '0' : '') + day;

// Set dates start and get actual date
var date1 = new Date('10/01/2012'); // Set the begninning date here
var date2 = new Date(actualDate);

var monday = Math.abs(date1.getTime() - date2.getTime()) / (1000 * 60 * 60 * 24 * 7);
monday -= 0.1;
monday = Math.floor(monday);
monday *= 1;

if (date1.getDay() == 1) monday += 1;
if (date2.getDay() == 1) monday += 1;

//$('').html(monday);
$("#showMondays").text(monday);

</pre></code>

This is the working monday counter: http://jsfiddle.net/hRaAF/

Thank you!

Aug 11 in Web Development by gaurav
• 18,960 points
37 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Web Development

0 votes
0 answers
0 votes
0 answers

When I delete data from jquery data-table it still showing in grid until refresh

I tried that table automatically refresh but ...READ MORE

Aug 19 in Web Development by gaurav
• 18,960 points
14 views
0 votes
1 answer

Jquery and Menu and logo

Seems your anchor tag is not visible ...READ MORE

answered Jun 22 in Web Development by rajatha
• 7,440 points
27 views
0 votes
0 answers

jQuery UI DatePicker - Change Date Format

I am using the UI DatePicker from ...READ MORE

Jun 23 in Web Development by gaurav
• 18,960 points
84 views
0 votes
1 answer

jQuery $(this) selector function and limitations

this isn't a jQuery "thing", but a basic JavaScript ...READ MORE

answered Jun 23 in Web Development by rajatha
• 7,440 points
25 views
0 votes
1 answer

Using Jquery Ajax to retrieve data from Mysql

Perform a AJAX GET request to get ...READ MORE

answered Jun 23 in Web Development by rajatha
• 7,440 points
932 views
0 votes
0 answers

How can I make a PHP counter?

I did this in Javascript but when ...READ MORE

Jun 7 in PHP by Kichu
• 19,040 points
23 views
0 votes
1 answer

jQuery counter to count up to a target number

Use the jQuery animate function to count ...READ MORE

answered Jun 20 in JQuery by rajatha
• 7,440 points
245 views
0 votes
0 answers

jQuery counter, counting down after reaching the number

I'm using a jQuery code for showing ...READ MORE

Jul 26 in Web Development by gaurav
• 18,960 points
91 views
0 votes
1 answer

how to get the count of non zero values in a row

In first part you should solve the ...READ MORE

answered Apr 4, 2018 in Tableau by Atul
• 10,230 points
2,189 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP