Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Actual Time to Integer?

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

    Actual Time to Integer?

    Hi,

    how can I convert the actual time which I assume I would get by
    xy = DateTime.Now.ToShortTimeString into an integer (like hmmss or hhmmss) to compare it with ToTime[0] integers?

    Thanks!

    #2
    Hi BillCh, you can use ToTime() to convert a .NET DateTime structure to an int value that represents time.

    Comment


      #3
      Is there a function that does the opposite? Turns an integer into a DateTime?

      I'm trying to find a way to have DateTimes as User Inputs.

      Comment


        #4
        Hi Mike_D, I'm not aware of one, but you can also create an input of type DateTime for this, here's how to create user defined inputs - http://www.ninjatrader-support2.com/...ead.php?t=5782

        Comment


          #5
          You need to convert ints to DateTimes manually.

          Code:
          someVariable = new DateTime(yyyy, mm, dd, hh, mm, ss);
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            how to control input formatting?

            See attachment for reference. I can get user param inputs to be DateTime based and that is great. However, it shows both the Date and the Time for my params. What I'd like to have is greater control on input format - kind of like an input mask for DateTime input.

            In image attached, StrategyBase seems to do this nicely - in the Timeframe category, the From and To are Date only type inputs allowed by user. And the Session begins (local time) and Session ends (local time) are Time only type inputs allowed by user.

            Is there anyway we can achieve this type of effect for end user? I want to have something similar to the From/To and also the Session begins/ends type of inputting by the end user for different params I'm setting up.

            Thanks,

            JD
            Attached Files

            Comment


              #7
              Not sure if this is what you want, but you could for example change the 'category' name under the input region properties...

              Comment


                #8
                No, I know how to change Category name and have played with that before. But this isn't essence of my post. I'm after how to control the formatting of the right hand column for DateTime type params. I see that the "From", "To", "Session begins (local time)", and "Session ends (local time)" within StrategyBase C# definition are all DateTime objects. Yet they can be controlled formatting wise - one half to be date only, the other half to be Time only. That is what I'd like to do too with my own custom DateTime parameters but I'm not sure if I can achieve that effect like shown in the attachment.

                Comment


                  #9
                  Thanks for clarifying, you can achieve this with two separate inputs - one of DataTime, the other of TimeSpan - http://msdn.microsoft.com/en-us/libr...n_members.aspx

                  Comment


                    #10
                    duration

                    Originally posted by NinjaTrader_Josh View Post
                    You need to convert ints to DateTimes manually.

                    Code:
                    someVariable = new DateTime(yyyy, mm, dd, hh, mm, ss);
                    Hi Josh,

                    I've used this method to get the duration between two DateTimes:
                    System.DateTime date1 = new System.DateTime(1996, 6, 3, 22, 15, 0);
                    System.DateTime date2 = new System.DateTime(1996, 12, 6, 13, 2, 0);
                    // diff1 gets 185 days, 14 hours, and 47 minutes.
                    System.TimeSpan diff1 = date2.Subtract(date1);

                    I've got the right solution with my setting but in this form:5.05:50:00. how can I format this value in other format? I 've used this: http://msdn.microsoft.com/en-us/library/az4se3k1.aspx, but it can't accept them.
                    I like to see it in form dd/hh/mm.
                    thanks a lot. Tom
                    Last edited by marotom; 05-16-2011, 10:22 AM.

                    Comment


                      #11
                      Hi Tom, this will not work as TimeSpan ToString conversion method offers no parameters, but I believe that might do the trick for you :

                      string test = (DateTime.MinValue + diff1).ToString("dd:hh:mm");

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      650 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      370 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      109 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      574 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      577 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X