Results 1 to 4 of 4

Thread: [RESOLVED] Help Novice with date conversion in Javascript

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    61

    Resolved [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?

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,538

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,760

    Re: Help Novice with date conversion in Javascript

    Quote Originally Posted by techgnome View Post
    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?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,538

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width