Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Casting Day of Week to an integer

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

    Casting Day of Week to an integer

    Hello:

    I am trying to cast the day of the week to an integer. I would like Sunday = 0, Monday = 1 ... Saturday = 6

    I use:

    int TheDayOfWeek = (int) DateTime.Now.DayOfWeek;

    I am getting an error stating TheDayOfWeek does not exist in the current context.

    How do you do this?

    Thank you

    #2
    Hi geekodude, thanks for posting. This snippet works on my end:

    Code:
    int x = (int)DateTime.Now.DayOfWeek;
    Print(x);

    Comment


      #3
      Hi Chris:

      Thanks for the reply. I just ran your snippet in a script under playback Market Data for the week of 5/7/22 to 5/11/22. I get a value of 5 for the whole session of 5/7/22 to 5/11/22. This makes sense since today is Friday. However, the result is not what is desired.

      For example, I want to compare a trading date range in which the user inputs the StartTradingDay = 1 and EndTradingDay.=3 corresponding to trading on Monday through Wednesday. So how would I cast a statement whereby the date corresponds to Market Replay Date? The data output should be 6 for 5/7/22, 0 for 5/8/22 and so on.

      Thank you

      Comment


        #4
        Hi geekodude, you would want to use the Time[] array to get historical timestamps. DateTime.Now will return the current system time.

        Print((int)Time[0].DayOfWeek);

        Comment


          #5
          Perfect, thank you!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          54 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          131 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X