0

I don't know if this is possible with jquery. Can you detect the current date? And if for each day passed the specific date it adds 1.

So day 0= 04/02/2012

<h1>0</h1>

day 1= 05/02/2012

<h1>1</h1>

day 2= 06/02/2012

<h1>2</h1>

As a way to counting how long the day the website has been active. Or is there a better way to do this?

Thanks.

uriah
  • 2,485
  • 5
  • 28
  • 40

2 Answers2

1

Javascript has the Date Object

Christoph
  • 50,121
  • 21
  • 99
  • 128
1

If you just want to know if it's a different day, something as simple as this would work:

var DayDiff = function (start) {
    var now = new Date().getTime();
    start = new Date(start).getTime();

    return Math.floor((now - start)/ 86400000);
};

document.write(DayDiff('2012-02-01')); // Today is 2/3, this would print "2"

JSFiddle: http://jsfiddle.net/zfBrv/

Robert
  • 21,110
  • 9
  • 55
  • 65