Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Working with dates around month end

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

    Working with dates around month end

    I am using a formula

    ToDay(Time[0]) == date-2

    where date is in 20120702 (int) format, it works fine for the month, but for a month end it wont work,

    Is there a simple solution to take a date stored as an int to work around month ends, just to take away 2 days or so?

    Thanks

    Tinkerz

    #2
    Hello Tinkerz,
    If you try the below code then are you getting the correct values.

    Code:
    if (ToDay(Time[0]) == ToDay(new DateTime(2012, 7, 2).AddDays(-2)))
    {
    	//do something
    }
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      My date time is a list of dates in int format to I am matching them up

      The numbers will be changing all the time, so
      (2012, 7, 2)
      will change to 20120702, how can I make that bit change inline with my date integer?

      Comment


        #4
        Hello tinkerz,
        You have to either use a List of DateTime (List<DateTime>) or you can further custom code it and extract the year, month and day from the integer.

        For example to find the year you can use the below function.

        Code:
        private int IntToYear(int date)
        {
                   return (int)(date / 10000);
        }
        And call it from the code as

        Code:
        int year = IntToYear(20121026);
        JoydeepNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        157 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        91 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        143 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        131 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        107 views
        0 likes
        Last Post CarlTrading  
        Working...
        X