Web Analytics Made Easy -
StatCounter How to get no of weeks from the current date to join date using javascript - CodingForum

Announcement

Collapse
No announcement yet.

How to get no of weeks from the current date to join date using javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • deathshadow
    replied
    Unfortunately now you've lost all formatting AND some essential whitespace, so it's invalid code.

    Posting code on this site has been a broken DISASTER for months now. I generally have to put bbcode CODE tags in my snippet BEFORE I paste it, otherwise it strips ALL whitespace.

    Code:
    var
        date1 = new Date(), // today
        date2 = new Date(2020, 01, 01), // 1 January 2020
        days = Math.floor((date1 - date2) / 86400000),
        weeks = Math.floor(days / 7),
        overflowDays = days % 7;
    
    alert(weeks + ' weeks and ' + overflowDays + ' Days');


    Leave a comment:


  • sunfighter
    replied
    "editor with syntax highlighting" - yes it is. Never happened before. Thanks VIP

    Leave a comment:


  • VIPStephan
    replied
    Originally posted by sunfighter View Post
    Why is this in unreadable colors!!!
    Could it be that you copied it from some code editor with syntax highlighting? Anyway, you can remove any custom formatting with the second button from the left in the editor toolbar (the one labelled Tx).

    Leave a comment:


  • sunfighter
    replied
    Why is this in unreadable colors!!!

    Leave a comment:


  • sunfighter
    replied
    getTime() returns the number of milliseconds since January 1, 1970.
    (1000*60*60*24*7) converts to number of weeks
    Code:
    <!DOCTYPE html>
    <html>
    <body>
    <script>
    functiondiff_minutes(dt2,dt1)
    {
    varnumWeeks=((dt2.getTime()-dt1.getTime())/(1000*60*60*24*7));
    returnMath.abs(Math.round(numWeeks));// To remove fractions of a week
    }
    dt1=newDate();//Today
    dt2=newDate(2020,01,01);//Feb first
    alert(diff_minutes(dt1,dt2));
    </script>
    </body>
    </html>
    Use your dates
    Last edited by VIPStephan; Jun 15, 2020, 05:20 PM. Reason: removed colors

    Leave a comment:


  • How to get no of weeks from the current date to join date using javascript

    Hello!
    I want to get no of weeks from the current date to join date using javascript
Working...
X