I have a simple code and was trying to test that my code will return bar's yr/mo/date vs today's yr/mo/date.
However when I run it to get the month -getMonth()- it returns chart's bar Month as 7 and PCclock Month as 6. Today is Aug 1 and it appears correctly with debug of:
today = new Date();
BarDay = new Date(getValue("time",0));
What did I do wrong? I ran it on 30 min charts as well as 1 min
CODE:
var todayBar;
var today;
var chartDOW; //<<Day of Week
var PCclockDOW;
var chartDay;
var PCclockDay;
var chartMon;
var PCclockMon;
var chartYr;
var PCclockYr;
function preMain(){
setStudyTitle("Day Test");
setShowCursorLabel(false);
}
function main(){
//if (getBarState() == BARSTATE_NEWBAR ){
today = new Date();
BarDay = new Date(getValue("time",0));
chartDOW = today.getDay();
PCclockDOW = BarDay.getDay();
chartDay = today.getDate();
PCclockDay = BarDay.getDate();
chartMon= today.getMonth();
PCclockMon= BarDay.getMonth();
chartYr= today.getYear();
PCclockYr= BarDay.getYear();
debugPrintln("==================================== ==================");
debugPrintln("today==="+today);
debugPrintln("todaybar==="+BarDay);
debugPrintln(" today>PCclockDOW = "+PCclockDOW+" BarDay>chartDOW = "+chartDOW);
debugPrintln(" today>PCclockDay = "+PCclockDay+" BarDay>chartDay = "+chartDay);
debugPrintln(" today>PCclockMon = "+PCclockMon+" BarDay>chartMon = "+chartMon);
debugPrintln(" today>PCclockYr = "+PCclockYr+" BarDay>chartYr = "+chartYr);
//} //end barstate
}
However when I run it to get the month -getMonth()- it returns chart's bar Month as 7 and PCclock Month as 6. Today is Aug 1 and it appears correctly with debug of:
today = new Date();
BarDay = new Date(getValue("time",0));
What did I do wrong? I ran it on 30 min charts as well as 1 min
CODE:
var todayBar;
var today;
var chartDOW; //<<Day of Week
var PCclockDOW;
var chartDay;
var PCclockDay;
var chartMon;
var PCclockMon;
var chartYr;
var PCclockYr;
function preMain(){
setStudyTitle("Day Test");
setShowCursorLabel(false);
}
function main(){
//if (getBarState() == BARSTATE_NEWBAR ){
today = new Date();
BarDay = new Date(getValue("time",0));
chartDOW = today.getDay();
PCclockDOW = BarDay.getDay();
chartDay = today.getDate();
PCclockDay = BarDay.getDate();
chartMon= today.getMonth();
PCclockMon= BarDay.getMonth();
chartYr= today.getYear();
PCclockYr= BarDay.getYear();
debugPrintln("==================================== ==================");
debugPrintln("today==="+today);
debugPrintln("todaybar==="+BarDay);
debugPrintln(" today>PCclockDOW = "+PCclockDOW+" BarDay>chartDOW = "+chartDOW);
debugPrintln(" today>PCclockDay = "+PCclockDay+" BarDay>chartDay = "+chartDay);
debugPrintln(" today>PCclockMon = "+PCclockMon+" BarDay>chartMon = "+chartMon);
debugPrintln(" today>PCclockYr = "+PCclockYr+" BarDay>chartYr = "+chartYr);
//} //end barstate
}
Comment