Not sure why my code is printing old date

I am converting the javascript date into oracle date format and it keeps on printing old date. Please consider the following code. I was expecting 13-DEC-2016 to get printed in the alert ("Printing Full Date: "+fullStartOracleDate); dialog but it keeps on printing 2-DEC-2016 for some reason. It’s demonstrated in the JSFiddle here.

Here is my code :

var assignedOnDate = "12/13/2016";
var  myJSDate = new Date(assignedOnDate);

alert ("Printing Date: "+assignedOnDate);

var monthNames =  ["JAN", "FEB", "MAR", "APR", "MAY", "JUN",
                "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ];
  var month = myJSDate.getMonth();
  var year = myJSDate.getFullYear();
  var day = myJSDate.getDay();
  console.log("Month: "+month+" Year: "+year+" and Day: "+day)
  var fullStartOracleDate  = day+"-"+monthNames[month]+"-"+year;
  alert ("Printing Full Date: "+fullStartOracleDate);

Hi there Jack_Tauson_Sr,


   var day = myJSDay.getDay();

…gives the numerical day of the week - ( 0=“Sunday”, to 6=“Saturday” )

So use this…

   var day = myJSDate.getDate();

…which gives the numerical day of the month - ( 1 to 31 ).


Hi @coothead ,

Great. Thanks a lot !

          No problem, you’re very welcome. :sunglasses:


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.