Announcement

Collapse
No announcement yet.

problem with getDay() ?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem with getDay() ?

    The "general" documentation says:
    getDay() – Returns the day of the week of the date object according to local time.
    getDay() returns a value between 0 and 6.
    Return Values:
    0 = Sunday
    1 = Monday
    2 = Tuesday
    3 = Wednesday
    4 = Thursday
    5 = Friday
    6= Saturday
    var today = new Date();
    var days = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
    var dayOfWeek = today.getDay();
    var sDay = "Today is: " + days[dayOfWeek];

    I seem to experience 2 kinds of problems.
    1. Sometimes the result of "dow" is the day of month (1 thru 31)
    2. Sometimes the result is the same integer for all bars (the integer appears to be the day of the week, ex: 2 for tuesday)
    3. Sometimes, not sure what it's showing.

    HELP
    How can I get the day of week properly?

    Thank you in advance.

    Code:

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("test");
    }

    function main() {
    var indcurr = getCurrentBarIndex();
    var today = new Date();
    var dayOfWeek = today.getDay();
    debugPrintln("indcurr="+indcurr+" dow="+dayOfWeek);
    }

  • #2


    every time function you will need

    Comment


    • #3
      david,

      thanks for the reply. but the EFS you linked to does not address the "day of week".

      phil

      Comment


      • #4
        today = new Date;
        my_day = today.getDate();//this is day of week, 0=sun, 1=mon
        my_month = today.getMonth() + 1;
        my_year = today.getFullYear();

        Comment


        • #5
          Perhaps my PC is not configured correctly.
          I ran your code and dow value is = 4 for all bars.
          Can you try?

          function preMain() {
          setPriceStudy(true);
          setStudyTitle("test");
          }

          function main() {
          var indcurr = getCurrentBarIndex();
          var today = new Date;
          var my_day = today.getDate();//this is day of week, 0=sun, 1=mon
          debugPrintln("indcurr="+indcurr+" dow="+my_day);
          }

          Comment


          • #6
            documentation says:
            getDate() - Returns the day of the month of the date object according to local time.
            getDate() returns a value between 1 and 31.


            so 4 is ok. today is March 4.

            When I use getDay() as in documentation to get "day of week", I get "2" which is Tuesday (also correct) but for all the bars, which is incorrect.

            Comment


            • #7
              getDay checks todays date, not the date of the bar.

              try getValue("Day") or "Date"

              Comment


              • #8


                says

                Additional notes about "time" and "rawtime".

                In the early days of EFS, we discovered that using getValue("time", ...) put an extra load on the CPU. We do not recommend using getValue("time", ...).

                Instead, use one of the getYear(...), getMonth(...), getDay(...), getHour(...), getMinute(...), getSecond(...) functions. or getValue("rawtime", ...)

                rawtime is the number of seconds elapsed since 1/1/1970.


                __________________
                Matt Gundersen
                Director Desktop Software, eSignal

                Comment


                • #9
                  also,

                  Additionally, getValue can be called which in turn calls the functions above.


                  getValue(bartype [, nRelativeOffset [, nNumBars, [, Symbol ] ] ] )



                  Where barType is:


                  "Open"
                  "High"
                  "Low"
                  "Close"
                  "Time"
                  "rawtime"
                  "volume"
                  "oi"
                  "year"
                  "month"
                  "day"
                  "hour"
                  "minute"
                  "second"

                  Comment


                  • #10
                    so...
                    my problem is that i am not passing the right parameter to getDay():
                    var today = new Date();
                    var dayOfWeek = today.getDay();

                    It's passing today's date, so it's getting a 2 (tuesday).

                    The question is now, how do I obtain the date of a bar so that getDay() understands it, right?

                    I guess I need help with that. How do you get proper values for getYear(...), getMonth(...), getDay(...), getHour(...), getMinute(...), getSecond(...) etc for any given bar?

                    The documentation says Date() accepts rawtime as input so ...

                    I tried:

                    function main() {
                    var indcurr = getCurrentBarIndex();
                    var vrawtime = getValue("rawtime");
                    var vdate = new Date(vrawtime);
                    var dow = vdate.getDay(vdate);
                    debugPrintln("indcurr="+indcurr+" vdate="+vdate+" dow="+dow);
                    }

                    I get:
                    Jan 12, 1970 date for vdate for all bars (using daily).

                    Comment


                    • #11
                      I think I finally Unconfused myself.
                      Your link didn't have the day-of-week but it gave me info on how to get yr,mo,day of the bar, which I used to get the date object needed for the getDay() function.
                      Thanks very much.

                      I realize the new Date() is CPU intensive but that's all I can think of. If you have any better idea, please let me know. Thanks again.

                      function main() {
                      var indcurr = getCurrentBarIndex();
                      var BarYr = getValue("Year");
                      var BarMon = getValue("Month");
                      var BarDay = getValue("Day");
                      var BarYrMonDayInt= BarYr*10000+BarMon*100+BarDay*1;
                      var vdate = new Date(BarYr,BarMon-1,BarDay);
                      var dow = vdate.getDay(vdate);
                      //debugPrintln("indcurr="+indcurr+" yr="+BarYr+" mm="+BarMon+" dd="+BarDay);
                      debugPrintln("indcurr="+indcurr+" vdate="+vdate+" dow="+dow);
                      }

                      Comment

                      Working...
                      X