Javascript - criteria date and loop date doesnt match











up vote
0
down vote

favorite












This is part of code. Rest of code works but on this part Ive stuck and I dont know why!



function rndDATgen(F){

var fRNG = SpreadsheetApp.getActiveRange();
var fROW = fRNG.getRow();

var ss = SpreadsheetApp.getActiveSpreadsheet();
var SRCsheet = ss.getSheetByName("Dates");
var DSTsheet = ss.getActiveSheet();


var rngDATE = SRCsheet.getDataRange();
var valDATE = rngDATE.getValues();

var colSRNG = DSTsheet.getRange('A1:ZZ7');
var colVALUES = colSRNG.getValues();

var stDAT = DSTsheet.getRange("S1").getValue();
var enDAT = DSTsheet.getRange("S2").getValue();

var DSTclr = 7;
var DSTrow = 7;
var nDAT = 0;
var DSTlr = 7;
var DSTc = DSTsheet.getRange(1, 9, 500,1);
var DSTvalues = DSTc.getValues();


while (DSTvalues[DSTlr - 1][0] != ""){
DSTlr++;
}
DSTlr = DSTlr - 1;

var totRNGstat = DSTsheet.getRange('T7:T' + DSTlr);
var totRNGvalSTAT = totRNGstat.getValues();

var totRNG = SRCsheet.getRange('A1:A100');
var totRNGval = totRNG.getValues();

var totRNGdat = DSTsheet.getRange('S7:S' + DSTlr);
var totRNGvalDAT = totRNG.getValues();

var stDATrow = 0;
var enDATrow = 0;

for (var i=0; i<100; i++) {
if (totRNGval[i] == stDAT) {
stDATrow = i + 1;
}
}


In this last chunk of code Ive tried to iterate to find where in array is certain date (start date in this case = stDAT and range totRNGval)! By trying to return stDAT and totRNGval[i], both returns date in same format 01/01/2018. I ve tried as value too, but still no luck!



for (var i=0; i<100; i++) {
if (totRNGval[i] == stDAT) {
stDATrow = i + 1;
}
}


When I return value, it is always 0 but for sure there is excact date in range as start date.



Ive also check manually and it is same value (without floats) and it does find it with any other function: MATCH, VLOOKUP...! Ive tried changing == to ===, but no luck!



Why in loop start date isnt recognized when comparing with elements of array?










share|improve this question




















  • 1




    Possible duplicate of Compare two dates with JavaScript
    – TheMaster
    Nov 19 at 22:19






  • 1




    Also, totRNGval is a 2D dimensional array[[A1],[A2]]. A1 can be accessed by totRNGval[0][0]
    – TheMaster
    Nov 19 at 22:23












  • @TheMaster. Ive tried as [i][0] too! No luck.
    – Ivan Kočiš
    Nov 19 at 22:29












  • I linked a duplicate post that might explain how to compare dates in js
    – TheMaster
    Nov 19 at 22:32










  • @TheMaster, yes I saw it. Im trying that one now. Just need to adjust code a bit!
    – Ivan Kočiš
    Nov 19 at 22:55















up vote
0
down vote

favorite












This is part of code. Rest of code works but on this part Ive stuck and I dont know why!



function rndDATgen(F){

var fRNG = SpreadsheetApp.getActiveRange();
var fROW = fRNG.getRow();

var ss = SpreadsheetApp.getActiveSpreadsheet();
var SRCsheet = ss.getSheetByName("Dates");
var DSTsheet = ss.getActiveSheet();


var rngDATE = SRCsheet.getDataRange();
var valDATE = rngDATE.getValues();

var colSRNG = DSTsheet.getRange('A1:ZZ7');
var colVALUES = colSRNG.getValues();

var stDAT = DSTsheet.getRange("S1").getValue();
var enDAT = DSTsheet.getRange("S2").getValue();

var DSTclr = 7;
var DSTrow = 7;
var nDAT = 0;
var DSTlr = 7;
var DSTc = DSTsheet.getRange(1, 9, 500,1);
var DSTvalues = DSTc.getValues();


while (DSTvalues[DSTlr - 1][0] != ""){
DSTlr++;
}
DSTlr = DSTlr - 1;

var totRNGstat = DSTsheet.getRange('T7:T' + DSTlr);
var totRNGvalSTAT = totRNGstat.getValues();

var totRNG = SRCsheet.getRange('A1:A100');
var totRNGval = totRNG.getValues();

var totRNGdat = DSTsheet.getRange('S7:S' + DSTlr);
var totRNGvalDAT = totRNG.getValues();

var stDATrow = 0;
var enDATrow = 0;

for (var i=0; i<100; i++) {
if (totRNGval[i] == stDAT) {
stDATrow = i + 1;
}
}


In this last chunk of code Ive tried to iterate to find where in array is certain date (start date in this case = stDAT and range totRNGval)! By trying to return stDAT and totRNGval[i], both returns date in same format 01/01/2018. I ve tried as value too, but still no luck!



for (var i=0; i<100; i++) {
if (totRNGval[i] == stDAT) {
stDATrow = i + 1;
}
}


When I return value, it is always 0 but for sure there is excact date in range as start date.



Ive also check manually and it is same value (without floats) and it does find it with any other function: MATCH, VLOOKUP...! Ive tried changing == to ===, but no luck!



Why in loop start date isnt recognized when comparing with elements of array?










share|improve this question




















  • 1




    Possible duplicate of Compare two dates with JavaScript
    – TheMaster
    Nov 19 at 22:19






  • 1




    Also, totRNGval is a 2D dimensional array[[A1],[A2]]. A1 can be accessed by totRNGval[0][0]
    – TheMaster
    Nov 19 at 22:23












  • @TheMaster. Ive tried as [i][0] too! No luck.
    – Ivan Kočiš
    Nov 19 at 22:29












  • I linked a duplicate post that might explain how to compare dates in js
    – TheMaster
    Nov 19 at 22:32










  • @TheMaster, yes I saw it. Im trying that one now. Just need to adjust code a bit!
    – Ivan Kočiš
    Nov 19 at 22:55













up vote
0
down vote

favorite









up vote
0
down vote

favorite











This is part of code. Rest of code works but on this part Ive stuck and I dont know why!



function rndDATgen(F){

var fRNG = SpreadsheetApp.getActiveRange();
var fROW = fRNG.getRow();

var ss = SpreadsheetApp.getActiveSpreadsheet();
var SRCsheet = ss.getSheetByName("Dates");
var DSTsheet = ss.getActiveSheet();


var rngDATE = SRCsheet.getDataRange();
var valDATE = rngDATE.getValues();

var colSRNG = DSTsheet.getRange('A1:ZZ7');
var colVALUES = colSRNG.getValues();

var stDAT = DSTsheet.getRange("S1").getValue();
var enDAT = DSTsheet.getRange("S2").getValue();

var DSTclr = 7;
var DSTrow = 7;
var nDAT = 0;
var DSTlr = 7;
var DSTc = DSTsheet.getRange(1, 9, 500,1);
var DSTvalues = DSTc.getValues();


while (DSTvalues[DSTlr - 1][0] != ""){
DSTlr++;
}
DSTlr = DSTlr - 1;

var totRNGstat = DSTsheet.getRange('T7:T' + DSTlr);
var totRNGvalSTAT = totRNGstat.getValues();

var totRNG = SRCsheet.getRange('A1:A100');
var totRNGval = totRNG.getValues();

var totRNGdat = DSTsheet.getRange('S7:S' + DSTlr);
var totRNGvalDAT = totRNG.getValues();

var stDATrow = 0;
var enDATrow = 0;

for (var i=0; i<100; i++) {
if (totRNGval[i] == stDAT) {
stDATrow = i + 1;
}
}


In this last chunk of code Ive tried to iterate to find where in array is certain date (start date in this case = stDAT and range totRNGval)! By trying to return stDAT and totRNGval[i], both returns date in same format 01/01/2018. I ve tried as value too, but still no luck!



for (var i=0; i<100; i++) {
if (totRNGval[i] == stDAT) {
stDATrow = i + 1;
}
}


When I return value, it is always 0 but for sure there is excact date in range as start date.



Ive also check manually and it is same value (without floats) and it does find it with any other function: MATCH, VLOOKUP...! Ive tried changing == to ===, but no luck!



Why in loop start date isnt recognized when comparing with elements of array?










share|improve this question















This is part of code. Rest of code works but on this part Ive stuck and I dont know why!



function rndDATgen(F){

var fRNG = SpreadsheetApp.getActiveRange();
var fROW = fRNG.getRow();

var ss = SpreadsheetApp.getActiveSpreadsheet();
var SRCsheet = ss.getSheetByName("Dates");
var DSTsheet = ss.getActiveSheet();


var rngDATE = SRCsheet.getDataRange();
var valDATE = rngDATE.getValues();

var colSRNG = DSTsheet.getRange('A1:ZZ7');
var colVALUES = colSRNG.getValues();

var stDAT = DSTsheet.getRange("S1").getValue();
var enDAT = DSTsheet.getRange("S2").getValue();

var DSTclr = 7;
var DSTrow = 7;
var nDAT = 0;
var DSTlr = 7;
var DSTc = DSTsheet.getRange(1, 9, 500,1);
var DSTvalues = DSTc.getValues();


while (DSTvalues[DSTlr - 1][0] != ""){
DSTlr++;
}
DSTlr = DSTlr - 1;

var totRNGstat = DSTsheet.getRange('T7:T' + DSTlr);
var totRNGvalSTAT = totRNGstat.getValues();

var totRNG = SRCsheet.getRange('A1:A100');
var totRNGval = totRNG.getValues();

var totRNGdat = DSTsheet.getRange('S7:S' + DSTlr);
var totRNGvalDAT = totRNG.getValues();

var stDATrow = 0;
var enDATrow = 0;

for (var i=0; i<100; i++) {
if (totRNGval[i] == stDAT) {
stDATrow = i + 1;
}
}


In this last chunk of code Ive tried to iterate to find where in array is certain date (start date in this case = stDAT and range totRNGval)! By trying to return stDAT and totRNGval[i], both returns date in same format 01/01/2018. I ve tried as value too, but still no luck!



for (var i=0; i<100; i++) {
if (totRNGval[i] == stDAT) {
stDATrow = i + 1;
}
}


When I return value, it is always 0 but for sure there is excact date in range as start date.



Ive also check manually and it is same value (without floats) and it does find it with any other function: MATCH, VLOOKUP...! Ive tried changing == to ===, but no luck!



Why in loop start date isnt recognized when comparing with elements of array?







javascript loops google-apps-script google-sheets






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 22:11

























asked Nov 19 at 20:48









Ivan Kočiš

11




11








  • 1




    Possible duplicate of Compare two dates with JavaScript
    – TheMaster
    Nov 19 at 22:19






  • 1




    Also, totRNGval is a 2D dimensional array[[A1],[A2]]. A1 can be accessed by totRNGval[0][0]
    – TheMaster
    Nov 19 at 22:23












  • @TheMaster. Ive tried as [i][0] too! No luck.
    – Ivan Kočiš
    Nov 19 at 22:29












  • I linked a duplicate post that might explain how to compare dates in js
    – TheMaster
    Nov 19 at 22:32










  • @TheMaster, yes I saw it. Im trying that one now. Just need to adjust code a bit!
    – Ivan Kočiš
    Nov 19 at 22:55














  • 1




    Possible duplicate of Compare two dates with JavaScript
    – TheMaster
    Nov 19 at 22:19






  • 1




    Also, totRNGval is a 2D dimensional array[[A1],[A2]]. A1 can be accessed by totRNGval[0][0]
    – TheMaster
    Nov 19 at 22:23












  • @TheMaster. Ive tried as [i][0] too! No luck.
    – Ivan Kočiš
    Nov 19 at 22:29












  • I linked a duplicate post that might explain how to compare dates in js
    – TheMaster
    Nov 19 at 22:32










  • @TheMaster, yes I saw it. Im trying that one now. Just need to adjust code a bit!
    – Ivan Kočiš
    Nov 19 at 22:55








1




1




Possible duplicate of Compare two dates with JavaScript
– TheMaster
Nov 19 at 22:19




Possible duplicate of Compare two dates with JavaScript
– TheMaster
Nov 19 at 22:19




1




1




Also, totRNGval is a 2D dimensional array[[A1],[A2]]. A1 can be accessed by totRNGval[0][0]
– TheMaster
Nov 19 at 22:23






Also, totRNGval is a 2D dimensional array[[A1],[A2]]. A1 can be accessed by totRNGval[0][0]
– TheMaster
Nov 19 at 22:23














@TheMaster. Ive tried as [i][0] too! No luck.
– Ivan Kočiš
Nov 19 at 22:29






@TheMaster. Ive tried as [i][0] too! No luck.
– Ivan Kočiš
Nov 19 at 22:29














I linked a duplicate post that might explain how to compare dates in js
– TheMaster
Nov 19 at 22:32




I linked a duplicate post that might explain how to compare dates in js
– TheMaster
Nov 19 at 22:32












@TheMaster, yes I saw it. Im trying that one now. Just need to adjust code a bit!
– Ivan Kočiš
Nov 19 at 22:55




@TheMaster, yes I saw it. Im trying that one now. Just need to adjust code a bit!
– Ivan Kočiš
Nov 19 at 22:55












1 Answer
1






active

oldest

votes

















up vote
0
down vote













On the end I've bypassed this problem, simply by adding formula in "T1:T2" =Match(T1, DATES!A:A,0) and calling value from T1 & T2 with getValue().



Still, If anyone knows why my script didn't worked on first please I would like to learn it!






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382411%2fjavascript-criteria-date-and-loop-date-doesnt-match%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    On the end I've bypassed this problem, simply by adding formula in "T1:T2" =Match(T1, DATES!A:A,0) and calling value from T1 & T2 with getValue().



    Still, If anyone knows why my script didn't worked on first please I would like to learn it!






    share|improve this answer

























      up vote
      0
      down vote













      On the end I've bypassed this problem, simply by adding formula in "T1:T2" =Match(T1, DATES!A:A,0) and calling value from T1 & T2 with getValue().



      Still, If anyone knows why my script didn't worked on first please I would like to learn it!






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        On the end I've bypassed this problem, simply by adding formula in "T1:T2" =Match(T1, DATES!A:A,0) and calling value from T1 & T2 with getValue().



        Still, If anyone knows why my script didn't worked on first please I would like to learn it!






        share|improve this answer












        On the end I've bypassed this problem, simply by adding formula in "T1:T2" =Match(T1, DATES!A:A,0) and calling value from T1 & T2 with getValue().



        Still, If anyone knows why my script didn't worked on first please I would like to learn it!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 22:23









        Ivan Kočiš

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382411%2fjavascript-criteria-date-and-loop-date-doesnt-match%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]