Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Number of Days between two dates?

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

    Number of Days between two dates?

    Hey guys,

    What I want to have is an "int" value (in # of days) that is derived from the current date and a future date, which happens to be the expiration date of a futures contract.

    I can pull the Expiration Date out (Instrument.Expiry), and I can pull the current date (Using, DateTime.Now) but I personally cannot convert those to an int, double etc that I need to do some math with it.

    Thanks in advance for the help.

    #2
    Ah the joys..

    only took a few more hours to find out someone made it easy.. ToDay();

    Done and working.

    Comment


      #3
      Wait a minute guys. That only works for front month? It will not give me the numbers of days between now and expiration of a contract that is beyond the current month, so now I am back to the drawing board unless I want to try and do some convoluted figuring with the integers which is not the way to go.

      So I'm back to my original problem - counting the number of day between 'now' and expiration of any contract. Sorry about jumping the gun.

      Here's an example: Current date using ToDay() function is: 20130511. The Expiry date is 20130621 so the integer value subtracting one from the other is 111. Well that's correct, but clearly not what I want.

      Comment


        #4
        Ah .DayOfYear fits the bill.

        Excellent conversation with myself as I trip through this mess.

        Comment


          #5
          http://stackoverflow.com/questions/1...eft-difference


          Originally posted by Steve R View Post
          Wait a minute guys. That only works for front month? It will not give me the numbers of days between now and expiration of a contract that is beyond the current month, so now I am back to the drawing board unless I want to try and do some convoluted figuring with the integers which is not the way to go.

          So I'm back to my original problem - counting the number of day between 'now' and expiration of any contract. Sorry about jumping the gun.

          Here's an example: Current date using ToDay() function is: 20130511. The Expiry date is 20130621 so the integer value subtracting one from the other is 111. Well that's correct, but clearly not what I want.

          Comment


            #6
            yeah i'm sure the answer is in that mess somewhere, but I gotta tell ya I'm glad I tripped over the 2 simple lines that gave me the integer with pretty much zero fuss. Thx.

            Comment


              #7
              Actually bro, I took the time to slave over your link and made a much better product in the end. Just want to let you know.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Felix Reichert, 04-26-2024, 02:12 PM
              10 responses
              67 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by PaulMohn, 04-24-2024, 03:49 AM
              4 responses
              35 views
              0 likes
              Last Post PaulMohn  
              Started by lightsun47, Today, 11:37 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_Zachary  
              Started by vitaly_p, Yesterday, 05:09 PM
              4 responses
              35 views
              0 likes
              Last Post vitaly_p  
              Started by bortz, 11-06-2023, 08:04 AM
              50 responses
              1,773 views
              0 likes
              Last Post carnitron  
              Working...
              X