Announcement

Collapse
No announcement yet.

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 Hwop38, 05-04-2026, 07:02 PM
          0 responses
          161 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Started by CaptainJack, 04-24-2026, 11:07 PM
          0 responses
          310 views
          0 likes
          Last Post CaptainJack  
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          245 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          350 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          179 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Working...
          X