This repository contains all the functions to manage and manipulate javascript dates, such as getting the time in am and pm format or getting the fullYear.
Hope these functions will help and save time.
function isValidDate(value) {
var dateWrapper = new Date(value);
return !isNaN(dateWrapper.getDate());
}
function compareNumberOfDays(startDate,endDate) {
return result = startDate.getDay() - endDate.getDay();
}
function getMonthName(today) {
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
return monthNames[today.getMonth()]
}
function compareTimeBetweenTwoDates(date1, date2) {
var timediff = (date1.getTime() - date2.getTime()) / 1000; // time in seconds
return timediff / 60 // time in minutes
}
function formatAMPM(date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
}