Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8620565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:36:45+00:00 2026-06-12T06:36:45+00:00

I need a date string with one digit for the month, one digit for

  • 0

I need a date string with one digit for the month, one digit for the day and two digits for the year (which is M/d/yy in the US, d/M/yy in most other places). I also need it to work across locales so it should automatically deal with the order of month/day and the separator. The closest to this is the d format which returns MM/dd/yyyy when called via date.ToString("d").

This needs to work across locales, so I tried this is what I came up with:

string format = culture.DateTimeFormat.ShortDatePattern
                                   .Replace("yyyy", "yy")
                                   .Replace("dd", "d")
                                   .Replace("MM", "M");

return date.ToString(format);

Using culture.DateTimeFormat.ShortDatePattern gives me the date format used for the d date format. Using this property will take care of the ordering of day/month/year and the date separator.

Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:36:46+00:00Added an answer on June 12, 2026 at 6:36 am

    If you definitely want exactly the format M/d/yy then just use that:

    return date.ToString("M/d/yy", culture);
    

    However, that isn’t necessarily an appropriate string for the culture. For example, it would be rather alien to anyone in the UK, which would expect more of a d/M/yy format – day before month.

    Note that the MM/dd/yyyy format may be what you get when you use date.ToString("d") but that’s definitely not what you’d get in the UK.

    Basically, you need to decide whether you want to nail down the format, in which case you’re blowing localization – or whether you want to use the “normal” culture-specific short date string format, in which case date.ToString("d", culture) would make sense.

    It sounds like you may be trying to go half way – “the short date format, but definitely don’t use 4-digit years” etc. While that could work (make sure you pass culture into the ToString method as well) there’s no guarantee that the culture’s short date pattern will be using dd etc to start with. It could go horribly wrong, for example if the normal short date format is ddd dd MMM yyyy you’d end up with dd d MM yy, so something like “09 9 06 12” for June 9th 2012.

    Basically, unless you’ve actually got a mapping from culture to “even shorter date format” I wouldn’t suggest fudging it like this.

    EDIT: Here’s a short program whose output you should check. Basically it prints the original format and the modified one.

    using System;
    using System.Globalization;
    
    class Program
    {
        public static void Main()
        {
            foreach (var culture in 
                            CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                string original = culture.DateTimeFormat.ShortDatePattern;
                string modified = original.Replace("yyyy", "yy")
                                          .Replace("dd", "d")
                                          .Replace("MM", "M");
                Console.WriteLine("{0,11}: {1,12} => {2,-9}",
                                  culture, original, modified);
            }
        }
    }
    

    On my machine, scanning down the list quickly, I think you’d actually be okay. Nothing seems to use ddd or MMM in the original format. But there’s no guarantee that that will continue to be the case…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert my string date to datetime type. Here's one date scenario:
I need to get the date as one string and the current time as
I need to compare 2 string dates to see if one date is later
i have take one string array which stored date in format of 2012-04-26T08:38:00. i
I need to send a date as a string to a webserver with the
I need to reformat a string containing a date without using code behind. The
I need to obtain a Date object from this String:This is a example) M-27\nJUN-2012
I need to convert a timestamp string to java.util.Date . E.g.: MMDDYYHHMMSS to MM-DD-YY
I need to parse an RFC 2822 string representation of a date in Java.
The application need write file's last modification date. void Dater(String DateFile) { File file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.