0
$(function () {
    debugger;
    var nowTemp = new Date();
    var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
    var checkin = $('#_startdate').datepicker({
        language: 'en-US',
        onRender: function (date) {
            debugger;
            return date.valueOf() < now.valueOf() ? 'disabled' : '';
        }
    }).on('changeDate', function (ev) {
        if (ev.date.valueOf() > checkout.date.valueOf()) {
            var newDate = new Date(ev.date)
            newDate.setDate(newDate.getDate() + 1);
            checkout.setValue(newDate);
        }
        checkin.hide();
        $('#_enddate')[0].focus();
    }).data('datepicker');

    var checkout = $('#_enddate').datepicker({
        onRender: function (date) {
            return date.valueOf() <= checkin.date.valueOf() ? 'disabled' : '';
        }
    }).on('changeDate', function (ev) {
        checkout.hide();
    }).data('datepicker');
}); 

I am trying to run this code but, var nowTemp = new Date(); shows an invalid date and I don't know why? Any suggestions?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
R K Sharma
  • 845
  • 8
  • 23
  • 42

2 Answers2

0

You are creating an empty date with new Date()

If you want the current date you can use $.now()

StSoma
  • 1
0

nothing to worry about. But if you want the actual reason, look at the CMS note on this answer : https://stackoverflow.com/a/9725453/2143734

Community
  • 1
  • 1
Zzirconium
  • 431
  • 1
  • 10
  • 32
  • thanks man, but by this i can't solve my prob...can u please tell me a simple solution because i m new to jquery thanks – R K Sharma Oct 25 '13 at 15:29
  • It looks like you are trying to use a date picker (https://github.com/najlepsiwebdesigner/foundation-datepicker ?) but you did not say what is your actual problem doing so. As I said, the "invalid date" thing you get at the beginning cannot trigger a functional problem. – Zzirconium Oct 25 '13 at 15:51
  • i am following [link](http://www.eyecon.ro/bootstrap-datepicker/) this tutorial check in and check out but not getting the proper result – R K Sharma Oct 25 '13 at 15:57
  • the simple datepicker is working fine but i am not able to hide the past dates. then i put a debugger on the top of my code, and i have seen this when i the process reached at 'var nowTemp = new Date();' i am getting date in format like 'Fir 08 10' but i am also getting invalid date in prototype – R K Sharma Oct 25 '13 at 16:02
  • this is exactly what i want. thanks dude. i will try this code if then i will let u know, dose it work or ? ;) – R K Sharma Oct 25 '13 at 16:09
  • Sure, but this code is not mine ;) all the credit goes to this guy : http://stackoverflow.com/a/8356601/2143734 – Zzirconium Oct 25 '13 at 16:10
  • no its not working. dates not hiding, i am getting `var dates = $("#from, #to").datepicker({` undefined in `dates` – R K Sharma Oct 25 '13 at 16:21
  • in `var dateToday = new Date();` i am getting the value `Fri Oct 25 21:47:57 UTC+0530 2013` but when when i inspect it with `debugger` and expend the `+` i got `[prototype] invalid date` :( – R K Sharma Oct 25 '13 at 16:26
  • Well, as I said, you cannot make any assumption that this particular Invalid Date thing on the prototype. As long as you have an actual date in the value, do not worry about the prototype part display. However, I do not understand the "dates not hiding". Did you start from the code within the fiddle ? Because this one does hide dates previous to today, right ? – Zzirconium Oct 28 '13 at 08:21