Skip to content

Intellectaco/javascript-dates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

javascript-dates

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.

Check if date is valid

function isValidDate(value) {
    var dateWrapper = new Date(value);
    return !isNaN(dateWrapper.getDate());
}

Compare Number of Days between two dates

function compareNumberOfDays(startDate,endDate) {
		return result = startDate.getDay() - endDate.getDay();
}

Get Full Month Name

function getMonthName(today) {
		var monthNames = ["January", "February", "March", "April", "May", "June",
				  "July", "August", "September", "October", "November", "December"
				];
    return monthNames[today.getMonth()]
}

Compare Time Between two dates

function compareTimeBetweenTwoDates(date1, date2) {
	var timediff = (date1.getTime() - date2.getTime()) / 1000; // time in seconds
  return timediff / 60 // time in minutes
}

Time in AM/PM Format

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published