Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Before you can compare dates, they must be dates... In your example they are both strings so try something like this : </p> <pre><code>function validateDate() { var one_day=1000*60*60*24; serverDateTime="2012-11-23 17:06:46"; txtDate.value="30-Nov-2012" var _dtSvr = Date.parse(serverDateTime); var _dtTxt = Date.parse(txtDate.value); if (((_dtTxt - _dtSvr)/one_day) &gt; 7){ alert("Appointment can be fixed for next seven days only from current day."); return false; }else{ return true; } } </code></pre> <p>Try this and change the values of txtDate.value. I also recommend that you do extra verification on the formats in order for your dates to be correctly understood. Have a look on <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date" rel="nofollow">MDN Date</a> for all the details of date/time in javascript</p> <p>EDIT</p> <p>I tried this exactly in the Chrome (v23.xxx) console :</p> <pre><code>function validateDate(serverDateTime, txtDate) { var dateDifference; pickedDate = Date.parse(txtDate.replace(/-/g, " ")); todaysDate = new Date(serverDateTime); todaysDate.setHours(0, 0, 0, 0); dateDifference = Math.abs(Number(todaysDate) - pickedDate); //7 Days=604800000ms if (dateDifference &gt; 604800000) { return false; } else { return true; } } </code></pre> <p>Then I tried this :</p> <pre><code>validateDate("2012-11-23 17:06:46", "30-Nov-2012") </code></pre> <p>which returns "true" and tried this : </p> <pre><code>validateDate("2012-11-23 17:06:46", "30-Dec-2012") </code></pre> <p>which returns "false"</p> <p>It looks like this answers your question and further issues are nothing to do with the algo but more like how your browser interprets it and how you manage it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload