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 Mindset, 04-21-2026, 06:46 AM
          0 responses
          93 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          138 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          68 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          123 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          73 views
          0 likes
          Last Post PaulMohn  
          Working...
          X