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

Adding the Day of the Week

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

    Adding the Day of the Week

    Hi Support and Community,

    Is adding the Day of the Week posiible to the string message?Let`s say the message looks like this:

    "Message generated at 11.07.2013 18:00:11"

    Is it possible to add the name of the Day - Friday,Monday,etc...?

    Thanks

    #2
    Originally posted by cachevery View Post
    Hi Support and Community,

    Is adding the Day of the Week posiible to the string message?Let`s say the message looks like this:

    "Message generated at 11.07.2013 18:00:11"

    Is it possible to add the name of the Day - Friday,Monday,etc...?

    Thanks
    You can format a date however you want.

    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.

    Learn how to use a standard date and time format string to define the text representation of a date and time value in .NET.

    Comment


      #3
      Originally posted by cachevery View Post
      Hi Support and Community,

      Is adding the Day of the Week posiible to the string message?Let`s say the message looks like this:

      "Message generated at 11.07.2013 18:00:11"

      Is it possible to add the name of the Day - Friday,Monday,etc...?

      Thanks
      Suppose you have a DateTime object dt whose value indicates the generation time of the message. Then you need to format the message like this:

      Code:
      string message = "Message generated at " + dt.ToString("[B]dddd[/B], MM.dd.yyyy HH:mm:ss");
      The message will look like: "Message generated at Friday, 11.07.2013 18:00:11"

      Or you can directly access the day-of-week value by using:
      Code:
      dt.DayOfWeek
      Pi
      Last edited by ninZa; 06-12-2014, 09:10 PM.
      ninZa
      NinjaTrader Ecosystem Vendor - ninZa.co

      Comment


        #4
        Originally posted by koganam View Post
        You can format a date however you want.

        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.

        http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx
        Hi Koganam,

        thanks for your reply.I`m confused a bit with this line: DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15);

        Console.WriteLine(date1.ToString("dddd dd MMMM",
        CultureInfo.CreateSpecificCulture("en-US")));
        // Displays Friday 29 August


        In the message.Do i have to specify the Year as well?

        Comment


          #5
          You can learn from these examples:


          DateTime dt = DateTime.Now;
          String strDate="";
          strDate = dt.ToString("MM/dd/yyyy"); // 07/21/2007
          strDate = dt.ToString("dddd, dd MMMM yyyy"); //Saturday, 21 July 2007
          strDate = dt.ToString("dddd, dd MMMM yyyy HH:mm"); // Saturday, 21 July 2007 14:58
          strDate = dt.ToString("dddd, dd MMMM yyyy hh:mm tt"); // Saturday, 21 July 2007 03:00 PM
          strDate = dt.ToString("dddd, dd MMMM yyyy H:mm"); // Saturday, 21 July 2007 5:01
          strDate = dt.ToString("dddd, dd MMMM yyyy h:mm tt"); // Saturday, 21 July 2007 3:03 PM
          strDate = dt.ToString("dddd, dd MMMM yyyy HH:mm:ss"); // Saturday, 21 July 2007 15:04:10
          strDate = dt.ToString("MM/dd/yyyy HH:mm"); // 07/21/2007 15:05
          strDate = dt.ToString("MM/dd/yyyy hh:mm tt"); // 07/21/2007 03:06 PM
          strDate = dt.ToString("MM/dd/yyyy H:mm"); // 07/21/2007 15:07
          strDate = dt.ToString("MM/dd/yyyy h:mm tt"); // 07/21/2007 3:07 PM
          strDate = dt.ToString("MM/dd/yyyy HH:mm:ss"); // 07/21/2007 15:09:29
          strDate = dt.ToString("MMMM dd"); // July 21
          strDate = dt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK"); // 2007-07-21T15:11:19.1250000+05:30
          strDate = dt.ToString("ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"); // Sat, 21 Jul 2007 15:12:16 GMT
          strDate = dt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss"); // 2007-07-21T15:12:57
          strDate = dt.ToString("HH:mm"); // 15:14
          strDate = dt.ToString("hh:mm tt"); // 03:14 PM
          strDate = dt.ToString("H:mm"); // 5:15
          strDate = dt.ToString("h:mm tt"); // 3:16 PM
          strDate = dt.ToString("HH:mm:ss"); // 15:16:29
          strDate = dt.ToString("yyyy'-'MM'-'dd HH':'mm':'ss'Z'"); // 2007-07-21 15:17:20Z
          strDate = dt.ToString("dddd, dd MMMM yyyy HH:mm:ss"); // Saturday, 21 July 2007 15:17:58
          strDate = dt.ToString("yyyy MMMM"); // 2007 July
          ninZa
          NinjaTrader Ecosystem Vendor - ninZa.co

          Comment


            #6
            Originally posted by ninZa View Post
            Suppose you have a DateTime object dt whose value indicates the generation time of the message. Then you need to format the message like this:

            Code:
            string message = "Message generated at " + dt.ToString("[B]dddd[/B], MM.dd.yyyy HH:mm:ss");
            The message will look like: "Message generated at Friday, 11.07.2013 18:00:11"

            Or you can directly access the day-of-week value by using:
            Code:
            dt.DayOfWeek
            Pi
            Hi NinZa,

            I have the following line in the code:

            string body = subject + Environment.NewLine + Environment.NewLine + "Message generated at " + Time[0];
            SendMail( fromEmailAddress, emailAddress, subject, body );


            adding the " dt.ToString("dddd, MM.dd.yyyy HH:mm:ss");" generates errors.

            Comment


              #7
              Originally posted by cachevery View Post
              Hi NinZa,

              I have the following line in the code:

              string body = subject + Environment.NewLine + Environment.NewLine + "Message generated at " + Time[0];
              SendMail( fromEmailAddress, emailAddress, subject, body );


              adding the " dt.ToString("dddd, MM.dd.yyyy HH:mm:ss");" generates errors.
              In your case, Time[0] must replace the dt variable. Therefore, your code needs to be changed to:

              DateTime dt = Time[0];
              string body = subject + Environment.NewLine + Environment.NewLine + "Message generated at " + dt.ToString("dddd, MM.dd.yyyy HH:mm:ss");
              SendMail( fromEmailAddress, emailAddress, subject, body );
              Hope this helps
              Pi
              ninZa
              NinjaTrader Ecosystem Vendor - ninZa.co

              Comment


                #8
                Originally posted by ninZa View Post
                In your case, Time[0] must replace the dt variable. Therefore, your code needs to be changed to:



                Hope this helps
                Pi
                I LLLLLLLOVE IT!!!!!!

                Thanks NinZa,the only thing is that it gives the Day name with the lower case,not in capital.

                Comment


                  #9
                  Originally posted by cachevery View Post
                  I LLLLLLLOVE IT!!!!!!

                  Thanks NinZa,the only thing is that it gives the Day name with the lower case,not in capital.
                  Hi,

                  The code produces day names like these: Friday, Monday, Tuesday... Only the first letter is capitalized.

                  If you want day names to be all in capital (FRIDAY, MONDAY, TUESDAY...), please change your code to:

                  DateTime dt = Time[0];
                  string time = dt.DayOfWeek.ToString().ToUpper() + ", " + dt.ToString("MM.dd.yyyy HH:mm:ss");
                  string body = subject + Environment.NewLine + Environment.NewLine + "Message generated at " + time;
                  SendMail( fromEmailAddress, emailAddress, subject, body );
                  Pi
                  ninZa
                  NinjaTrader Ecosystem Vendor - ninZa.co

                  Comment


                    #10
                    Originally posted by ninZa View Post
                    Hi,

                    The code produces day names like these: Friday, Monday, Tuesday... Only the first letter is capitalized.

                    If you want day names to be all in capital (FRIDAY, MONDAY, TUESDAY...), please change your code to:



                    Pi
                    No,i get the Day`s name in the lower case,like this: "message generated at friday....etc..."...

                    But i`ll try this snippet.

                    Thanks

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Barry Milan, Yesterday, 10:35 PM
                    5 responses
                    16 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by DanielSanMartin, Yesterday, 02:37 PM
                    2 responses
                    13 views
                    0 likes
                    Last Post DanielSanMartin  
                    Started by DJ888, 04-16-2024, 06:09 PM
                    4 responses
                    12 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by terofs, Today, 04:18 PM
                    0 responses
                    11 views
                    0 likes
                    Last Post terofs
                    by terofs
                     
                    Started by nandhumca, Today, 03:41 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post nandhumca  
                    Working...
                    X