Get all the dates between two dates - Javascript andrey четверг, 3 июля 2014 г. No Comment

We can do this using Javascript's Date() object. You can use this following function to get between two dates. It will return array. Here we are using isDate() and isValidRange() functions to make sure is the given string is Date and end date is not greater then start date. If the given string is not date, then it will return "error occured!!!... Please Enter Valid Dates" in browser console and it will return empty array.

Parameters:

Start - Starting Date
end - Ending Date
Note: you should pass Date object as parameters.
If you are using jQuery Date picker, you can get selected date object like below,
var start = $("#from").datepicker("getDate"),
end = $("#to").datepicker("getDate");
you can get selected date object using 'getDate' parameter in datepicker.

usage and Example :

If you are using datepicker, you can use this code,
var start = $("#from").datepicker("getDate"),
end = $("#to").datepicker("getDate");

var between = getDates(start, end);

If you are going to use your own date string, you should make it as date object. Then only you can use in it. You can use this piece of code,
var start = new Date('2014-07-13'),
end = new Date('2014-07-17');


var between = getDates(start, end);

Live Demo

Have any doubt, feel free to comment here!

We can do this using Javascript's Date() object. You can use this following function to get between two dates. It will return array. Here we are using isDate() and isValidRange() functions to make sure is the given string is Date and end date is not greater then start date. If the given string is not date, then it will return "error occured!!!... Please Enter Valid Dates" in browser console and it will return empty array.

Parameters:

Start - Starting Date
end - Ending Date
Note: you should pass Date object as parameters.
If you are using jQuery Date picker, you can get selected date object like below,
var start = $("#from").datepicker("getDate"),
end = $("#to").datepicker("getDate");
you can get selected date object using 'getDate' parameter in datepicker.

usage and Example :

If you are using datepicker, you can use this code,
var start = $("#from").datepicker("getDate"),
end = $("#to").datepicker("getDate");

var between = getDates(start, end);

If you are going to use your own date string, you should make it as date object. Then only you can use in it. You can use this piece of code,
var start = new Date('2014-07-13'),
end = new Date('2014-07-17');


var between = getDates(start, end);

Live Demo

Have any doubt, feel free to comment here!

by Jillur Rahman

Jillur Rahman is a Web designers. He enjoys to make blogger templates. He always try to make modern and 3D looking Templates. You can by his templates from Themeforest.

Follow him @ Twitter | Facebook | Google Plus

No Comment