Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

System.DayOfWeek Problem

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

    System.DayOfWeek Problem

    Hi,
    In my indicator code have below lines:

    DateTime item3 = base.Time[1];
    int dayOfWeek = item3.DayOfWeek;
    DateTime dateTime3 = Time[0];
    int num = dateTime3.DayOfWeek;

    I got this error:
    Cannot implicitly convert type 'System.DayOfWeek' to 'int'. An explicit conversion exists (are you missing a cast?)

    Above functions not return integer?
    ow to solve that?
    Regards,

    #2
    Hello RezaFx,

    This error returns due to the fact that the DayOfWeek Enum is not an int or string.
    A proper use of DayOfWeek would be the following:
    Code:
    if(dateTime3.DayOfWeek == DayOfWeek.Monday)
    				Print("It is Monday.");
    For information on DayOfWeek please visit the following link: http://www.ninjatrader.com/support/h.../dayofweek.htm

    For a C# reference on DayOfWeek please visit the following link: http://msdn.microsoft.com/en-us/libr...(v=vs.90).aspx

    Please let me know if you have any questions.

    Comment


      #3
      Originally posted by RezaFx View Post
      Hi,
      In my indicator code have below lines:

      DateTime item3 = base.Time[1];
      int dayOfWeek = item3.DayOfWeek;
      DateTime dateTime3 = Time[0];
      int num = dateTime3.DayOfWeek;

      I got this error:
      Cannot implicitly convert type 'System.DayOfWeek' to 'int'. An explicit conversion exists (are you missing a cast?)

      Above functions not return integer?
      ow to solve that?
      Regards,
      If you insist on using an integer, you have to do an explicit cast.
      Code:
      int num = (int)dateTime3.DayOfWeek;

      Comment


        #4
        Thanks. Now it works.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        27 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        20 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        183 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        335 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        260 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X