Announcement

Collapse
No announcement yet.

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.

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

    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("dddd, 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
        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:
          http://www.codeproject.com/Articles/...eTime-ToString

          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("dddd, 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 schmidtbc16, Today, 03:36 PM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by RT001, Today, 03:25 PM
                    2 responses
                    12 views
                    0 likes
                    Last Post RT001
                    by RT001
                     
                    Started by mbrandau, Today, 01:58 PM
                    5 responses
                    33 views
                    0 likes
                    Last Post mbrandau  
                    Started by remcovdmeulen, Today, 02:15 PM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_Jim  
                    Started by gbrad, Today, 09:57 AM
                    7 responses
                    15 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X