I’ve got a little issue that hopefully someone can help out with. I have a CSV file called names2.csv with the following data
Name,Date \
George,6/15/2010 \
Smith,6/11/2010 \
And here’s the code
<html>
<head>
<title>CSV & Date parser</title>
<script type="text/javascript">
// From: http://codingforums.com/showthread.php?t=198171
function checkCSVdate() {
// ckDate = document.getElementById('dinfo').value;
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
ckDate = (month + "/" + day + "/" + year);
var str = '';
fso = new ActiveXObject("Scripting.FileSystemObject");
fin = fso.OpenTextFile("names2.csv", 1, false, 0);
var line = fin.ReadAll();
var tmp = line.split('\
');
for (var i=0; i<tmp.length; i++) {
temp = tmp[i].split(',');
if (ckDate == temp[1]) { str += tmp[i]; }
}
if (str == '') { document.getElementById('mtchDiv').innerHTML = 'No matches found'; }
else { document.getElementById('mtchDiv').innerHTML = str; }
}
onload = function() {
checkCSVdate();
}
</script>
</head>
<body>
<div id="mtchDiv"></div>
</body>
</html>
Since the data file has a line with 6/15/2010, it should return “George”, right? It returns “No Matches Found”.