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

  • 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
    ASP.Net Software Development

  • #2
    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
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

    Comment


    • #3
      Why is this in unreadable colors!!!
      Evolution - The non-random survival of random variants.
      Physics is actually atoms trying to understand themselves.

      Comment


      • #4
        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).
        Stop solving problems you don’t yet have!

        Comment


        • #5
          "editor with syntax highlighting" - yes it is. Never happened before. Thanks VIP
          Evolution - The non-random survival of random variants.
          Physics is actually atoms trying to understand themselves.

          Comment


          • #6
            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');


            I'll kill you and your dreams tonight, begin new life.
            Bleed your death upon me, let your bloodline feed my youth.
            https://cutcodedown.com

            Comment

            Working...
            X