Skip to content

Instantly share code, notes, and snippets.

@Octagon-simon
Created November 7, 2021 16:07
Show Gist options
  • Select an option

  • Save Octagon-simon/804c7d1e306fcbedcc517ae701e942ad to your computer and use it in GitHub Desktop.

Select an option

Save Octagon-simon/804c7d1e306fcbedcc517ae701e942ad to your computer and use it in GitHub Desktop.
function findNotifDate(date_notified = "2021-11-05 15:00:00") {
/**
* @ findNotifDate : Finds the Date Difference of a Notification
* @ date_notified : The notification date
**/
const date_sent_tmp = new Date(date_notified);
//Check for timestamps
if(date_notified.indexOf('-') != -1){
var date_sent = date_sent_tmp.getTime();
}else{
var date_sent = date_notified;
}
const date_now = new Date();
//current timestamp
var today = date_now.getTime();
//Subtract the timestamps
var calc = new Date(today - date_sent);
//Prevent Extra 1 Hour
calc.setHours( calc.getUTCHours() +0);
//Make our result readable
var calcDate = calc.getDate()+'-'+(calc.getMonth()+1)+'-'+calc.getFullYear(); //25-12-2021
var calcTime = calc.getHours()+':'+calc.getMinutes()+':'+calc.getSeconds(); //15:00:00
//Get How many days, months and years that has passed
var date_passed = calcDate.split("-");
var time_passed = calcTime.split(":");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment