![]() |
Trying to get the days between dates.
no regexp please. I feel my logic is sound on this but I'm definitely doing something wrong. Is it a logic error on my part or am I not passing Date.parse with the right value. I'm not sure please help! thank you for your replies! :)
Code:
//days between function only yyyy-mm-dd will work. |
Date.parse() *ALREADY* is giving you the milliseconds since 1/1/1970.
It is handing you simply a *NUMBER*. It is *NOT* giving you a Date object, so trying to do date.getTime() is giving you an error.Time to learn to DEBUG DEBUG DEBUG! Any good debugger (I prefer Chrome's, for integration and ease of use) would have shown you what was in date1 and date2. |
Ah! the little things haha; I shall go and do that. I use firebug by the way if theres really any difference between chromes. is there?
|
Why do you persist in copying the function arguments to other variables?
Why not simply: Code:
function daysBetween(firstd, secondd, str) Code:
function daysBetween(date1, date2, str) Code:
date1ms = date1.getTime(); //we convert both dates to milliseconds.Of course, now you know that you could have done simply Code:
var thedifference = Math.abs(date1 - date2); |
Quote:
Chrome does a better job of presenting variables, including scope variables, in my opinion. But it's not like either is any slouch. |
You are right about all of those; except to me its a little clearer at this stage because if I wanted to I could change those variable names without having to change the arguments, but I am a beginner.
Pertaining to all your other snippets I actually feel very good because I figured to do those after your first reply which was a great push in the right direction. I'll definitely have to try the chrome one for future projects and and compare on how much I like them, but thanks for the suggestion! |
| All times are GMT +1. The time now is 11:23 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.