Hi all
I have a json format which has two objects Created_date and Reply_date. Created_date has a date on which a message is created and the Reply_date tells when the user has replied to that messge. So I am getting the Created_date as follows

var createDate = new Date(Created_date);
var newDate = createDate.getDate();
var month = createDate.getMonth();
var monthArray = new Array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var year = createDate.getFullYear();
var compareMonth = monthArray(month);
var displayDate = compareMonth+ " "+ newDate+" , "+ year;
alert(displayDate);

So this returns the created date. Now I would like to compare the created date and the reply date. If both the created date and reply date are the same for example if both the created date and reply date are Apr 07 2014, then I would like to print "today" else I would like to print that particular day on which it was replied. So how do I do this guys any ideas?

In line 6 of your code, you're trying to access the monthArray with the wrong syntax. You should change that to:

var compareMonth = monthArray[month];

To get today's date in the same format as your displayDate, you can do:

var tempNow = new Date();
var today = monthArray[tempNow.getMonth()] + ' ' + tempNow.getDate() + ', ' + tempNow.getFullYear();

Then assign the string 'today' to displayDate if today's date and the display date are equal:

if (today === displayDate) {
  displayDate = 'today';
}

@Purkinje
Thanks for pointing out my mistake. I have changed the line no 6. I will work with that var today ...... soon and let you know the status of it.

Thanks,
Varun Krishna. P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.