I need to know how long the message was written.
window.date = function (o){
var r = new Date('1970-01-31 23:59:59').getTime();
var a = new Date().getTime()-new Date(o).getTime();
/*o=the date of the message: 2017-04-18 17:00:00*/
if(new Date().getFullYear()>new Date(o).getFullYear()){
n = 'more than a year ago';
}else if(new Date().getMonth()>new Date(o).getMonth()){
if(j=>r){
n = 'less than a month ago';
}else{
n = 'more than a month ago';
}
}else{
n = 'error'
}
The problems are these: 1)if you write a message on 31/03 you see after a day(01/04): 'more than a month ago'(it's only one day from the date) 2)if you write a message on 17/04 and today(18/04) you try to read you don't read 'less than a month ago', but you read 'error'. Really i try, but in this page i don't read the solution:https://www.w3schools.com/jsref/jsref_obj_date.asp Can you show me a hypothetical solution?
=>to>=in theifstatement.=>is an arrow function developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/…new Date().getFullYear()>new Date(o).getFullYear()so date is last day of year, opens it up the first day.... so it would be over a year ago with your check.If (dateToCheck < today-one month) { //over a month ago }- You can see basic implementation here.