Announcement

Collapse
No announcement yet.

Day of the week?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Day of the week?

    Hello,

    Does a function exist that returns the day of the week, like Monday, Tuesday, ecc., of the bar?
    Thank you in advance.
    Raffaele

  • #2
    Raffaele
    Create a date object of the bar time using the getValue("time") function and then use the getDay() method of the Date Object to retrieve the day of the week eg
    PHP Code:
    var  barDate getValue("time");
    var 
    dayOfWeek barDate.getDay(); 
    dayOfWeek will be a value from 0 to 6 where 0 is equal to Sunday, 1 is Monday, etc.
    Hope this helps
    Alex

    Comment


    • #3
      Hello Alexis,

      Thank you for your responce. That is exactly what I wanted.
      Raffaele

      Comment


      • #4
        Raffaele
        Always a pleasure.
        You can also write the example I provided in my previous reply as a function which you can easily add to any script where you need to determine the day of the week eg
        PHP Code:
        var dayOfWeek null;
        function 
        getDOW(){  
            if (
        getBarState()==BARSTATE_NEWBAR && day(0)!=day(-1)) {
                var 
        barDate getValue("time");
                
        dayOfWeek barDate.getDay()
            }    
            return (
        dayOfWeek);

        Then from main() you would simply need to call the function eg
        PHP Code:
        if(getDOW()==3){//if the day of the week is a Wednesday 
        Hope this helps
        Alex

        Comment

        Working...
        X