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;

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?

3 Years
Discussion Span
Last Post by Varunkrishna

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';

Edited by Purkinje: formatting


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.

Varun Krishna. P

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.