Days since a date
-
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
-
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
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.'