Search code examples
javascriptamchartsamcharts4

Read a file name by date on javascript


i'm trying to read a file by date with JS i tried to replace the varable TimeNow without success. when fo example i make fixed filename it works fine, but replacing the filename with a variable 'TimeNow' it doesnt work.

var prex = document.querySelector('pre');

var DateNow = new Date();
DateNow.setHours(DateNow.getHours()-1);

var TimeNow=DateNow.getFullYear() + "" + (DateNow.getMonth()+1) + "" + DateNow.getDate();
loadCSV("counters_test_directory_${TimeNow}.log");

prex.innerHTML += '\n\n';
prex.innerHTML += TimeNow;
<pre>
</pre>


Solution

  • loadCSV(`counters_test_directory_${TimeNow}.log`);
    

    var prex = document.querySelector('pre');
    
    var DateNow = new Date();
    DateNow.setHours(DateNow.getHours()-1);
    
    var TimeNow=DateNow.getFullYear() + "" + (DateNow.getMonth()+1) + "" + DateNow.getDate();
    alert(`counters_test_directory_${TimeNow}.log`);
    // The source of this function is NOT given.
    //loadCSV(`counters_test_directory_${TimeNow}.log`);
    
    prex.innerHTML += '\n\n';
    prex.innerHTML += TimeNow;
    <pre>
    </pre>