2

I am trying to compare some dates in javascript/jquery. But I am getting some error. What I did wrong here?

dayRender: function (date, cell) {
   console.log(date.getTime())
}   

//here am geting date.getTime is not a function

Here is my function:

 $scope.myFunction =function(balance){
    $('#fullCalendar').fullCalendar({
        defaultDate: balance.defaultDate,
        editable: true,
        eventLimit: true,           
        events: [
            {
                title: balance.title,
                start: balance.startDate                
            }
        ],

         dayRender: function (date, cell) {  // This is the callback function to modify a particular date cell.
            console.log(date.getDate());   //undefined
        }   
    });
}
shareef
  • 9,255
  • 13
  • 58
  • 89
krish
  • 1,077
  • 6
  • 24
  • 49
  • how are you calling the dayRender function. are you passing a date type object to it as the first argument. – abhit Nov 09 '17 at 05:34
  • what are you passing into those functions as the first argument? just because the argument is called date doesnt' mean it'll have date functions – Jaromanda X Nov 09 '17 at 05:35
  • It seems like date.getTime isn't a function! Seriously though, Without knowing what `date` is before it's passed to the function...any answer that someone gives you will just be a guess. – Jared Nov 09 '17 at 05:35
  • please check updated code. – krish Nov 09 '17 at 05:40
  • The definition of `date` is still missing. Maybe `date` was created by `new Date`, instead of `new Date()` ..? – Teemu Nov 09 '17 at 05:41
  • 1
    Log `date` instead of `date.getTime()` and tell us what the output is – Jared Nov 09 '17 at 05:44

2 Answers2

2

var date = new Date();
console.log(date.getDate());

Instead of passing date object everytime you call dayRender(), you can use date directly in that function.

dayRender: function (cell) {
  var date = new Date();
  console.log(date.getTime());
  console.log(date.getDate());
  console.log(date.getYear());
}   
abhit
  • 973
  • 3
  • 17
  • 40
  • how are you calling the `$scope.myFunction()`. here is a [fiddle](https://jsfiddle.net/o2gxgz9r/18168/) I have created with your code and it is working fine. the date you are receiving in in `dayRender()` is already a date type object. hence this might be some error in your code I have edited the code in your question copy that and try to run again. – abhit Nov 09 '17 at 06:37
  • so you want your calendar to show after you have clicked on grids? – abhit Nov 09 '17 at 06:42
  • i did what you are trying to do in this [fiddle](http://jsfiddle.net/fiddleJS/ADukg/15828/). works fine here.... are you sure `dayRender()` is inside `.fullCalendar()` call? – abhit Nov 09 '17 at 07:12
  • How `date.getDate()` is directly working in fiddle but for me its showing `date.getDate() is not a function` – krish Nov 09 '17 at 07:26
  • I have updated the fiddle according to your condition...see it http://jsfiddle.net/fiddleJS/ADukg/15831/ – abhit Nov 09 '17 at 07:31
  • buddy try to understand your fiddle is great.But to get date `date.get('date')` is not working for me.`date.get('date')` this only returns the date in my code. if I add `date.getDate()` then it throws `date.getDate() is not a function`.If I add `date.get('date')` background is not working :-( :-(seriously I tried alot But I couldn't solve it:-( – krish Nov 09 '17 at 07:37
  • okay do one thing.....create a fiddle for me with your controller code and template code and i will see from there where's the problem. – abhit Nov 09 '17 at 07:39
  • and more thing......why are you using `date.get('date')` instead of `date.getDate()` ? – abhit Nov 09 '17 at 07:41
  • was your calendar opening on clicking on grids. bcoz it is not opening in the fiddle. – abhit Nov 09 '17 at 07:55
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/158581/discussion-between-krish-and-lakshay). – krish Nov 09 '17 at 08:04
2

Try to convert date into date object hope it works

dayRender: function (date, cell) {
    dateObj =new Date(date);
    console.log(date.getDate());
}
HBK
  • 735
  • 1
  • 11
  • 29