I'm having some problems getting a date string (such as "17/08/2012") to a date so that it can be used to compare another date.
I would like "17/08/2012" to produce the date "17/08/2012 00:00:00 GMT" so that it can be used correctly for comparison. I thought this would be the easiest part of what I'm trying to do, but apparently not. Please see my current code below.
function dateToString(dateString) {
var dateArray = dateString.split("/");
var year = dateArray[2];
var month = dateArray[1];
var day = dateArray[0];
var date = new Date(year, month - 1, day);
return date;
}
This code currently produces "Fri Aug 17 16:00:00 PDT 2012" and I have absolutely no idea why it says 4pm. I have been trying loads of different ways of doing this for the past hour and still cannot seem to get it right. Any ideas how I can get it to convert correctly?
As always any help is much appreciated.