DateTime standard format for day, month and year











up vote
0
down vote

favorite












Is there any standard DateTime format for showing "[day] [month] [year]"?
I do not wish to use custom format strings, because it takes away the ability to have order of "day" and "month" depending on the country.
For example, for "en-us" it's "November 22", in France day is first, so it's "22 Novembre"



Just to display day and month like this, I know I can use "M" standard format string.



But how I can write "November 22, 2018" ?



Do I need to concatenate two strings like this:



$"{dt.ToString("M")}, {dt.ToString("yyyy")}"



Is there another way?










share|improve this question


















  • 1




    So what you want? "Day Month, Year", or every country with its own format?
    – SeM
    Nov 22 at 16:36












  • Every country with its own format
    – Don Box
    Nov 22 at 16:39










  • But just day month and year
    – Don Box
    Nov 22 at 16:39










  • What type is your project? WinForms, MVC, WPF..etc?
    – SeM
    Nov 22 at 16:40






  • 2




    It's WPF, but it shouldn't matter I think, it's NET
    – Don Box
    Nov 22 at 16:40















up vote
0
down vote

favorite












Is there any standard DateTime format for showing "[day] [month] [year]"?
I do not wish to use custom format strings, because it takes away the ability to have order of "day" and "month" depending on the country.
For example, for "en-us" it's "November 22", in France day is first, so it's "22 Novembre"



Just to display day and month like this, I know I can use "M" standard format string.



But how I can write "November 22, 2018" ?



Do I need to concatenate two strings like this:



$"{dt.ToString("M")}, {dt.ToString("yyyy")}"



Is there another way?










share|improve this question


















  • 1




    So what you want? "Day Month, Year", or every country with its own format?
    – SeM
    Nov 22 at 16:36












  • Every country with its own format
    – Don Box
    Nov 22 at 16:39










  • But just day month and year
    – Don Box
    Nov 22 at 16:39










  • What type is your project? WinForms, MVC, WPF..etc?
    – SeM
    Nov 22 at 16:40






  • 2




    It's WPF, but it shouldn't matter I think, it's NET
    – Don Box
    Nov 22 at 16:40













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Is there any standard DateTime format for showing "[day] [month] [year]"?
I do not wish to use custom format strings, because it takes away the ability to have order of "day" and "month" depending on the country.
For example, for "en-us" it's "November 22", in France day is first, so it's "22 Novembre"



Just to display day and month like this, I know I can use "M" standard format string.



But how I can write "November 22, 2018" ?



Do I need to concatenate two strings like this:



$"{dt.ToString("M")}, {dt.ToString("yyyy")}"



Is there another way?










share|improve this question













Is there any standard DateTime format for showing "[day] [month] [year]"?
I do not wish to use custom format strings, because it takes away the ability to have order of "day" and "month" depending on the country.
For example, for "en-us" it's "November 22", in France day is first, so it's "22 Novembre"



Just to display day and month like this, I know I can use "M" standard format string.



But how I can write "November 22, 2018" ?



Do I need to concatenate two strings like this:



$"{dt.ToString("M")}, {dt.ToString("yyyy")}"



Is there another way?







c# .net






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 16:33









Don Box

905721




905721








  • 1




    So what you want? "Day Month, Year", or every country with its own format?
    – SeM
    Nov 22 at 16:36












  • Every country with its own format
    – Don Box
    Nov 22 at 16:39










  • But just day month and year
    – Don Box
    Nov 22 at 16:39










  • What type is your project? WinForms, MVC, WPF..etc?
    – SeM
    Nov 22 at 16:40






  • 2




    It's WPF, but it shouldn't matter I think, it's NET
    – Don Box
    Nov 22 at 16:40














  • 1




    So what you want? "Day Month, Year", or every country with its own format?
    – SeM
    Nov 22 at 16:36












  • Every country with its own format
    – Don Box
    Nov 22 at 16:39










  • But just day month and year
    – Don Box
    Nov 22 at 16:39










  • What type is your project? WinForms, MVC, WPF..etc?
    – SeM
    Nov 22 at 16:40






  • 2




    It's WPF, but it shouldn't matter I think, it's NET
    – Don Box
    Nov 22 at 16:40








1




1




So what you want? "Day Month, Year", or every country with its own format?
– SeM
Nov 22 at 16:36






So what you want? "Day Month, Year", or every country with its own format?
– SeM
Nov 22 at 16:36














Every country with its own format
– Don Box
Nov 22 at 16:39




Every country with its own format
– Don Box
Nov 22 at 16:39












But just day month and year
– Don Box
Nov 22 at 16:39




But just day month and year
– Don Box
Nov 22 at 16:39












What type is your project? WinForms, MVC, WPF..etc?
– SeM
Nov 22 at 16:40




What type is your project? WinForms, MVC, WPF..etc?
– SeM
Nov 22 at 16:40




2




2




It's WPF, but it shouldn't matter I think, it's NET
– Don Box
Nov 22 at 16:40




It's WPF, but it shouldn't matter I think, it's NET
– Don Box
Nov 22 at 16:40












4 Answers
4






active

oldest

votes

















up vote
2
down vote













It does seem a little odd that the full option isn't available. The closest I can suggest is to use custom formatting, but rather than supply your own, grab DateTimeFormatInfo.LongDatePattern and strip out any occurrence of "dddd" (and its surrounding space/punctuation).



That should give you the variation you want across cultures while removing the weekday.





Examples:



  en-US => dddd, MMMM dd, yyyy => MMMM dd, yyyy => November 22, 2018

fr-FR => dddd d MMMM yyyy => d MMMM yyyy => 22 novembre 2018





share|improve this answer




























    up vote
    1
    down vote













    As I can understand the solution for your problem could be to create a new CultureInfo object.



    I've tested it.



    CultureInfo us = new CultureInfo("en-US");
    string usDate = us.DateTimeFormat.ShortDatePattern;

    CultureInfo fr = new CultureInfo("fr-FR");
    string frDate = fr.DateTimeFormat.ShortDatePattern;

    Console.WriteLine(usDate);
    Console.WriteLine(frDate);

    //Apply the country format here.
    var localDate = DateTime.Now.ToString(frDate);

    Console.WriteLine(localDate);


    So the format output will be as the location format you provide.



    M/d/yyyy ---> USA format.
    dd/MM/yyyy ---> France format.

    22/11/2018 ---> France format applied to the current date.


    For more information redirect to:
    CultureInfo Class






    share|improve this answer




























      up vote
      0
      down vote













      $"{dt.ToString("MMMM dd, yyyy")}"



      This will show it as November 22, 2018 assuming that dt is assigned this date.
      Also, check out Custom Date Time Format String.






      share|improve this answer

















      • 1




        Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
        – Don Box
        Nov 22 at 16:52










      • It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
        – Yeldar Kurmangaliyev
        Nov 22 at 16:52








      • 1




        My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
        – Raarge
        Nov 22 at 16:54






      • 1




        @Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
        – Dan Rayson
        Nov 22 at 16:58


















      up vote
      0
      down vote













      You can obtain the LongDatePattern from the current culture, then remove the day-of-week (dddd) and surrounding characters with a regular expression. Below, I am assuming that commas, periods, and spaces are the only separators, but if you encounter others you may want to modify the regex accordingly.



      string longDatePattern = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;
      string modifiedDatePattern = Regex.Replace(longDatePattern, @"[,.]?s?d{4}[,.]?s?", "");

      Console.WriteLine(longDatePattern); // "dddd, MMMM d, yyyy"
      Console.WriteLine(modifiedDatePattern); // "MMMM d, yyyy"


      Now you have a custom format you can apply:



      string s = DateTime.Now.ToString(modifiedDatePattern);

      Console.WriteLine(s); // "November 22, 2018"





      share|improve this answer





















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435102%2fdatetime-standard-format-for-day-month-and-year%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        2
        down vote













        It does seem a little odd that the full option isn't available. The closest I can suggest is to use custom formatting, but rather than supply your own, grab DateTimeFormatInfo.LongDatePattern and strip out any occurrence of "dddd" (and its surrounding space/punctuation).



        That should give you the variation you want across cultures while removing the weekday.





        Examples:



          en-US => dddd, MMMM dd, yyyy => MMMM dd, yyyy => November 22, 2018

        fr-FR => dddd d MMMM yyyy => d MMMM yyyy => 22 novembre 2018





        share|improve this answer

























          up vote
          2
          down vote













          It does seem a little odd that the full option isn't available. The closest I can suggest is to use custom formatting, but rather than supply your own, grab DateTimeFormatInfo.LongDatePattern and strip out any occurrence of "dddd" (and its surrounding space/punctuation).



          That should give you the variation you want across cultures while removing the weekday.





          Examples:



            en-US => dddd, MMMM dd, yyyy => MMMM dd, yyyy => November 22, 2018

          fr-FR => dddd d MMMM yyyy => d MMMM yyyy => 22 novembre 2018





          share|improve this answer























            up vote
            2
            down vote










            up vote
            2
            down vote









            It does seem a little odd that the full option isn't available. The closest I can suggest is to use custom formatting, but rather than supply your own, grab DateTimeFormatInfo.LongDatePattern and strip out any occurrence of "dddd" (and its surrounding space/punctuation).



            That should give you the variation you want across cultures while removing the weekday.





            Examples:



              en-US => dddd, MMMM dd, yyyy => MMMM dd, yyyy => November 22, 2018

            fr-FR => dddd d MMMM yyyy => d MMMM yyyy => 22 novembre 2018





            share|improve this answer












            It does seem a little odd that the full option isn't available. The closest I can suggest is to use custom formatting, but rather than supply your own, grab DateTimeFormatInfo.LongDatePattern and strip out any occurrence of "dddd" (and its surrounding space/punctuation).



            That should give you the variation you want across cultures while removing the weekday.





            Examples:



              en-US => dddd, MMMM dd, yyyy => MMMM dd, yyyy => November 22, 2018

            fr-FR => dddd d MMMM yyyy => d MMMM yyyy => 22 novembre 2018






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 at 16:50









            sellotape

            5,60021619




            5,60021619
























                up vote
                1
                down vote













                As I can understand the solution for your problem could be to create a new CultureInfo object.



                I've tested it.



                CultureInfo us = new CultureInfo("en-US");
                string usDate = us.DateTimeFormat.ShortDatePattern;

                CultureInfo fr = new CultureInfo("fr-FR");
                string frDate = fr.DateTimeFormat.ShortDatePattern;

                Console.WriteLine(usDate);
                Console.WriteLine(frDate);

                //Apply the country format here.
                var localDate = DateTime.Now.ToString(frDate);

                Console.WriteLine(localDate);


                So the format output will be as the location format you provide.



                M/d/yyyy ---> USA format.
                dd/MM/yyyy ---> France format.

                22/11/2018 ---> France format applied to the current date.


                For more information redirect to:
                CultureInfo Class






                share|improve this answer

























                  up vote
                  1
                  down vote













                  As I can understand the solution for your problem could be to create a new CultureInfo object.



                  I've tested it.



                  CultureInfo us = new CultureInfo("en-US");
                  string usDate = us.DateTimeFormat.ShortDatePattern;

                  CultureInfo fr = new CultureInfo("fr-FR");
                  string frDate = fr.DateTimeFormat.ShortDatePattern;

                  Console.WriteLine(usDate);
                  Console.WriteLine(frDate);

                  //Apply the country format here.
                  var localDate = DateTime.Now.ToString(frDate);

                  Console.WriteLine(localDate);


                  So the format output will be as the location format you provide.



                  M/d/yyyy ---> USA format.
                  dd/MM/yyyy ---> France format.

                  22/11/2018 ---> France format applied to the current date.


                  For more information redirect to:
                  CultureInfo Class






                  share|improve this answer























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    As I can understand the solution for your problem could be to create a new CultureInfo object.



                    I've tested it.



                    CultureInfo us = new CultureInfo("en-US");
                    string usDate = us.DateTimeFormat.ShortDatePattern;

                    CultureInfo fr = new CultureInfo("fr-FR");
                    string frDate = fr.DateTimeFormat.ShortDatePattern;

                    Console.WriteLine(usDate);
                    Console.WriteLine(frDate);

                    //Apply the country format here.
                    var localDate = DateTime.Now.ToString(frDate);

                    Console.WriteLine(localDate);


                    So the format output will be as the location format you provide.



                    M/d/yyyy ---> USA format.
                    dd/MM/yyyy ---> France format.

                    22/11/2018 ---> France format applied to the current date.


                    For more information redirect to:
                    CultureInfo Class






                    share|improve this answer












                    As I can understand the solution for your problem could be to create a new CultureInfo object.



                    I've tested it.



                    CultureInfo us = new CultureInfo("en-US");
                    string usDate = us.DateTimeFormat.ShortDatePattern;

                    CultureInfo fr = new CultureInfo("fr-FR");
                    string frDate = fr.DateTimeFormat.ShortDatePattern;

                    Console.WriteLine(usDate);
                    Console.WriteLine(frDate);

                    //Apply the country format here.
                    var localDate = DateTime.Now.ToString(frDate);

                    Console.WriteLine(localDate);


                    So the format output will be as the location format you provide.



                    M/d/yyyy ---> USA format.
                    dd/MM/yyyy ---> France format.

                    22/11/2018 ---> France format applied to the current date.


                    For more information redirect to:
                    CultureInfo Class







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 22 at 17:07









                    Angel Roma

                    13917




                    13917






















                        up vote
                        0
                        down vote













                        $"{dt.ToString("MMMM dd, yyyy")}"



                        This will show it as November 22, 2018 assuming that dt is assigned this date.
                        Also, check out Custom Date Time Format String.






                        share|improve this answer

















                        • 1




                          Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
                          – Don Box
                          Nov 22 at 16:52










                        • It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
                          – Yeldar Kurmangaliyev
                          Nov 22 at 16:52








                        • 1




                          My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
                          – Raarge
                          Nov 22 at 16:54






                        • 1




                          @Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
                          – Dan Rayson
                          Nov 22 at 16:58















                        up vote
                        0
                        down vote













                        $"{dt.ToString("MMMM dd, yyyy")}"



                        This will show it as November 22, 2018 assuming that dt is assigned this date.
                        Also, check out Custom Date Time Format String.






                        share|improve this answer

















                        • 1




                          Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
                          – Don Box
                          Nov 22 at 16:52










                        • It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
                          – Yeldar Kurmangaliyev
                          Nov 22 at 16:52








                        • 1




                          My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
                          – Raarge
                          Nov 22 at 16:54






                        • 1




                          @Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
                          – Dan Rayson
                          Nov 22 at 16:58













                        up vote
                        0
                        down vote










                        up vote
                        0
                        down vote









                        $"{dt.ToString("MMMM dd, yyyy")}"



                        This will show it as November 22, 2018 assuming that dt is assigned this date.
                        Also, check out Custom Date Time Format String.






                        share|improve this answer












                        $"{dt.ToString("MMMM dd, yyyy")}"



                        This will show it as November 22, 2018 assuming that dt is assigned this date.
                        Also, check out Custom Date Time Format String.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Nov 22 at 16:47









                        Raarge

                        1912




                        1912








                        • 1




                          Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
                          – Don Box
                          Nov 22 at 16:52










                        • It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
                          – Yeldar Kurmangaliyev
                          Nov 22 at 16:52








                        • 1




                          My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
                          – Raarge
                          Nov 22 at 16:54






                        • 1




                          @Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
                          – Dan Rayson
                          Nov 22 at 16:58














                        • 1




                          Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
                          – Don Box
                          Nov 22 at 16:52










                        • It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
                          – Yeldar Kurmangaliyev
                          Nov 22 at 16:52








                        • 1




                          My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
                          – Raarge
                          Nov 22 at 16:54






                        • 1




                          @Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
                          – Dan Rayson
                          Nov 22 at 16:58








                        1




                        1




                        Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
                        – Don Box
                        Nov 22 at 16:52




                        Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
                        – Don Box
                        Nov 22 at 16:52












                        It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
                        – Yeldar Kurmangaliyev
                        Nov 22 at 16:52






                        It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
                        – Yeldar Kurmangaliyev
                        Nov 22 at 16:52






                        1




                        1




                        My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
                        – Raarge
                        Nov 22 at 16:54




                        My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
                        – Raarge
                        Nov 22 at 16:54




                        1




                        1




                        @Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
                        – Dan Rayson
                        Nov 22 at 16:58




                        @Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
                        – Dan Rayson
                        Nov 22 at 16:58










                        up vote
                        0
                        down vote













                        You can obtain the LongDatePattern from the current culture, then remove the day-of-week (dddd) and surrounding characters with a regular expression. Below, I am assuming that commas, periods, and spaces are the only separators, but if you encounter others you may want to modify the regex accordingly.



                        string longDatePattern = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;
                        string modifiedDatePattern = Regex.Replace(longDatePattern, @"[,.]?s?d{4}[,.]?s?", "");

                        Console.WriteLine(longDatePattern); // "dddd, MMMM d, yyyy"
                        Console.WriteLine(modifiedDatePattern); // "MMMM d, yyyy"


                        Now you have a custom format you can apply:



                        string s = DateTime.Now.ToString(modifiedDatePattern);

                        Console.WriteLine(s); // "November 22, 2018"





                        share|improve this answer

























                          up vote
                          0
                          down vote













                          You can obtain the LongDatePattern from the current culture, then remove the day-of-week (dddd) and surrounding characters with a regular expression. Below, I am assuming that commas, periods, and spaces are the only separators, but if you encounter others you may want to modify the regex accordingly.



                          string longDatePattern = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;
                          string modifiedDatePattern = Regex.Replace(longDatePattern, @"[,.]?s?d{4}[,.]?s?", "");

                          Console.WriteLine(longDatePattern); // "dddd, MMMM d, yyyy"
                          Console.WriteLine(modifiedDatePattern); // "MMMM d, yyyy"


                          Now you have a custom format you can apply:



                          string s = DateTime.Now.ToString(modifiedDatePattern);

                          Console.WriteLine(s); // "November 22, 2018"





                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            You can obtain the LongDatePattern from the current culture, then remove the day-of-week (dddd) and surrounding characters with a regular expression. Below, I am assuming that commas, periods, and spaces are the only separators, but if you encounter others you may want to modify the regex accordingly.



                            string longDatePattern = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;
                            string modifiedDatePattern = Regex.Replace(longDatePattern, @"[,.]?s?d{4}[,.]?s?", "");

                            Console.WriteLine(longDatePattern); // "dddd, MMMM d, yyyy"
                            Console.WriteLine(modifiedDatePattern); // "MMMM d, yyyy"


                            Now you have a custom format you can apply:



                            string s = DateTime.Now.ToString(modifiedDatePattern);

                            Console.WriteLine(s); // "November 22, 2018"





                            share|improve this answer












                            You can obtain the LongDatePattern from the current culture, then remove the day-of-week (dddd) and surrounding characters with a regular expression. Below, I am assuming that commas, periods, and spaces are the only separators, but if you encounter others you may want to modify the regex accordingly.



                            string longDatePattern = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;
                            string modifiedDatePattern = Regex.Replace(longDatePattern, @"[,.]?s?d{4}[,.]?s?", "");

                            Console.WriteLine(longDatePattern); // "dddd, MMMM d, yyyy"
                            Console.WriteLine(modifiedDatePattern); // "MMMM d, yyyy"


                            Now you have a custom format you can apply:



                            string s = DateTime.Now.ToString(modifiedDatePattern);

                            Console.WriteLine(s); // "November 22, 2018"






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 22 at 17:03









                            Matt Johnson

                            134k40273396




                            134k40273396






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435102%2fdatetime-standard-format-for-day-month-and-year%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                What visual should I use to simply compare current year value vs last year in Power BI desktop

                                How to ignore python UserWarning in pytest?

                                Alexandru Averescu