-
Jul 21st, 2017, 05:00 AM
#1
Thread Starter
Member
[RESOLVED] Help Novice with date conversion in Javascript
Hi all, I'm a complete novice with Javascript so wondering if anybody can assist me with an issue I'm having.
On my webpage I have a minimum and maximum date set in hidden fields hdfMinDate and hdfMaxDate and are both string.
These values are passed into Javascript and it says min / max values on a date slider.
The min value is '2018.01.01'
The max value is '2018.09.01'
The code below correctly converts the min value to 1st Jan 2018 but the max value is getting converted to 31st Aug 2018
The actual values are in these url and what gets converted.
http://www.timestampgenerator.com/1514764800/
http://www.timestampgenerator.com/1535756400/
Is the function correct below? I don't know why my min date is converted to 1st Jan with 0 hours but the max date is converted to 31st Aug and 23 hours.
When i say I'm a novice the past couple of days are the first time I've had to look into it and have just about learnt how to step through it
Code:
// Create object to store filter for each group
var rangeFilters = {};
var $grid;
var MinDate = $("#hdfMinDate").val();
var MaxDate = $("#hdfMaxDate").val();
//Runs on load
$(function () {
$(".c-hosp-isotope__pak-sliders").hide();
initalise();
});
//Intialise all items to
function initalise() {
rangeFilters = {
'dateXYZ': {
'min': new Date(MinDate).getTime() / 1000,
'max': new Date(MaxDate).getTime() / 1000
}
};
Any ideas?
-
Jul 21st, 2017, 08:25 AM
#2
Re: Help Novice with date conversion in Javascript
I bet if you look, it's returning 31 Aug 2018 23:59pm ... which is the end of the month. Typically when you want a date range, it's usually from the start of some month (Jan 1, 00:00 - midnight) through the end of the month (31 Aug 23:59pm) So that's what it's doing... it's adjusting the max date/time to be one minute prior to the date you selected. This way any date in the range will be >= the min date and < max date.
-tg
-
Jul 21st, 2017, 10:09 AM
#3
Re: Help Novice with date conversion in Javascript
Originally Posted by techgnome
This way any date in the range will be >= the min date and < max date.
-tg
I did not know that. On a side note, is that why .NET's Random object works the same way, it provides a number >= the lower bounds and < the upper bounds?
-
Jul 21st, 2017, 10:56 AM
#4
Re: Help Novice with date conversion in Javascript
Beats me... But likely since it can return a double. Never quite thought about it in that way before. Makes some sense.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|