Date snippets
jQuery
by Sparrow Squire
JavaScript
///// Version 1
//var dateFrom = "10/12/2016";//dd/mm/yy
//var dateTo = "01/02/2017";//dd/mm/yy
////prettify todays date to dd/mm/yy format
//var todayDate = new Date();
//var dateCheck = todayDate.getDate() + "/" + (todayDate.getMonth()+1) + "/" + todayDate.getFullYear();
//var d1 = dateFrom.split("/");
//var d2 = dateTo.split("/");
//var c = dateCheck.split("/");
//var from = new Date(d1[2], parseInt(d1[1])-1, d1[0]); // -1 because months are from 0 to 11
//var to = new Date(d2[2], parseInt(d2[1])-1, d2[0]);
//var check = new Date(c[2], parseInt(c[1])-1, c[0]);
//if ((check > from && check < to) == true) {
// console.log("this is true");
//} else {
// console.log("this is false");
//}
///// Version 2
//var from = new Date("2016/12/10");
//var to = new Date("2017/02/02");
//var today = new Date();
//if ((today > from && today < to) == true) {
// if (today.toDateString() == new Date("2016/12/13").toDateString()) {
// console.log(today);
// } else {
// console.log("also false");
// console.log(today);
// }
//} else {
// console.log("this is false");
//}
///// Version 3
//Christmas
var fromChristmas = new Date("2016/12/13");
fromChristmas.setHours(14,01,0,0);
var toChristmas = new Date("2016/12/14");
//New Year
var fromNewYear = new Date("2016/12/13");
fromChristmas.setHours(18,01,0,0);
var toNewYear = new Date("2016/12/14");
//Today
var today = new Date();
if ((today > fromChristmas
&& today < toChristmas) == true) {
console.log("christmas" + today);
}
if ((today > fromNewYear
&& today < toNewYear) == true) {
console.log("New year" + today);
}