Date and Javascript
<p>So, I know this is probably a FAQ, but I can't seem to unravel it in my head. </p>

<p>In Javascript, I'm trying to create a count down timer without the use of cheating (meaning, borrowing someone's script), for our wedding date which happens to be in September. </p>

<p>I've know learned how difficult it is to convert days into Months and Days.</p>

<p>For those math guru's out there, is it possible to define each month in javascript and use it to count down, then follow up with an if statement that if the date passes, this is how many days have passed. I like math but I can't seem to figure out the formula and it's frustrating me. </p>

<p>Sept 22 is the day.</p>

<p>I know there are 183 days by time of this writing. I also hand counted the days to verify. I can get the formula to show me this. </p>

<p>But would it be a long winded "if statement" to include all of the months if I defined every month and the amount of days in that month? Or could it be a long expression? </p>

<pre><code>variable = weddingDate - (?)
</code></pre>

<p>I don't need it writen if someone can just help with some alegbra! :)</p>

<hr>

<p>Edit</p>

<pre><code>var d1, d2;

d1 = new Date('3/23/2012');
d2 = new Date('9/22/2012');

compare = d2-d1

document.write((compare) /1000 / 60 / 60 / 24);
</code></pre>

<p>So this returns the accurate number of days. This was actually much easier than people's made it out to be. I know I can change d1 that will auto update depending on the PC's date.</p>

<p>But, what's the formula to accurately convert from days into months and days?</p>

<p>I know you could take</p>

<pre><code> document.write((compare) /1000 / 60 / 60 / 24);
</code></pre>

<p>And change to</p>

<pre><code> document.write(((compare) /1000 / 60 / 60 / 24) / 30.4368499);
</code></pre>

<p>Then I could round to nearest integer which would be 6 (aka 6 months), then subtract that from the total, leaving me a decimal amount. I could then times this by 30.4368499. But I wasn't sure if there was a better way to do this.</p>
