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

Converting DateTime Values to customized format

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

    Converting DateTime Values to customized format

    Hi all,

    I have some problems converting some values into a user defined format.

    The code:

    Code:
    Print("Date1: " + ToDay(Time[0]).ToString());
    Print("Date2: " + ToDay(Time[0]).ToString("yyyy-MM-dd"));
    Print("Open: " + Open[0]);
    Print("High: " + High[0]);
    Print("Low: " + Low[0]);
    Print("Close: " + Close[0]);
    Print("Volume: " + Volume[0]);
    The result set:

    Date1: 20120127
    Date2: yyyy-MM-dd
    Open: 1314,75
    High: 1319,25
    Low: 1307
    Close: 1312,75
    Volume: 1730153


    Here my problem: I would like to have the date (as a string) in format: "YYYY-MM-DD" and all the the values with a "." instead of "," as seperator.

    Can anyone please provide some code snippets to me?


    Thanks in advance!

    Knoppers

    #2
    Here it is in all its glory, courtesy of a little Google-Fu.

    Learn to use custom date and time format strings to convert DateTime or DateTimeOffset values into text representations, or to parse strings for dates & times.

    Comment


      #3
      Hello Knoppers,
      Thanks for your post and I am happy to assist you.
      Please try these codes:
      Code:
      Print("Date1: " + Time[0].ToString("yyyy-MM-dd")); 
      Print("Date2: " + Time[0].ToString("yyyy-MM-dd")); 
      Print("Open: " + Open[0].ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US").NumberFormat)); 
      Print("High: " + High[0].ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US").NumberFormat));
      Print("Low: " + Low[0].ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US").NumberFormat));
      Print("Close: " + Close[0].ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US").NumberFormat));
      @koganam thanks for your input.

      Please let me know if I can assist you any further.
      JoydeepNinjaTrader Customer Service

      Comment


        #4
        Hi Joydeep & koganam,

        thanks a lot for your hints and your perfect support!

        Works perfectly...

        Comment


          #5
          Hello Knoppers,
          Glad to know it worked for you.

          Please let me know if I can assist you any further.
          JoydeepNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by kevinenergy, 02-17-2023, 12:42 PM
          117 responses
          2,766 views
          1 like
          Last Post jculp
          by jculp
           
          Started by Mongo, Today, 11:05 AM
          5 responses
          15 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by traderqz, Today, 12:06 AM
          8 responses
          16 views
          0 likes
          Last Post traderqz  
          Started by SightCareAubetter, Today, 12:50 PM
          0 responses
          2 views
          0 likes
          Last Post SightCareAubetter  
          Started by Skifree, Today, 03:41 AM
          5 responses
          14 views
          0 likes
          Last Post Skifree
          by Skifree
           
          Working...
          X