Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Days since a date

Days since a date

Scheduled Pinned Locked Moved Web Development
javascripthtmltoolshelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    harveyhanson
    wrote on last edited by
    #1

    I wondered if anyone could help. I want to write a script in a page to show the days since a certain date (which I would hard code into the script), so for example, on the screen it would show: "It has been xx days since this event" (where xx is the number of days) How would I do this, I could imagine it would be quite an easy javascript snipet using the dateadd function but I was not sure and couldnt find much on google to help. p.s. Currently using HTML on the page but am I write in thinking a snipet can be any language as it is just declared at the top of the snipet and closed at the end? Thanks

    S 1 Reply Last reply
    0
    • H harveyhanson

      I wondered if anyone could help. I want to write a script in a page to show the days since a certain date (which I would hard code into the script), so for example, on the screen it would show: "It has been xx days since this event" (where xx is the number of days) How would I do this, I could imagine it would be quite an easy javascript snipet using the dateadd function but I was not sure and couldnt find much on google to help. p.s. Currently using HTML on the page but am I write in thinking a snipet can be any language as it is just declared at the top of the snipet and closed at the end? Thanks

      S Offline
      S Offline
      Shog9 0
      wrote on last edited by
      #2

      How 'bout something like this?

      function DaysSince(date)
      {
         var msecPerDay = 1000*60*60*24;
         return Math.floor( (Date.now() - date) / msecPerDay );
      }

      // example:
      var days = DaysSince( new Date("2/3/2004") );

      Citizen 20.1.01

      'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups