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

  • Home
  • SEARCH
  • 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 8660667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:18:40+00:00 2026-06-12T16:18:40+00:00

I have a custom DateTime format string: M/d/yyyy h:m:ss tt . For example, with

  • 0

I have a custom DateTime format string: "M/d/yyyy h:m:ss tt".

For example, with the date ‘September 18th, 2012 @ noon’, I expect the output of this to be something like "9/18/2012 12:0:00 PM".

The time seems to be formatting properly, but the date portion is getting messed up. I am seeing the dates formatted as "MM-dd-yyyy" and I can’t figure out why.

Here is some sample code to reproduce the problem:

var datetime = DateTime.Now;
Console.WriteLine("Date: " + datetime.ToString("MMMM d, yyyy"));       // Date: October 11, 2012 --> correct
Console.WriteLine("Date: " + datetime.ToString("M/d/yyyy h:m:ss tt")); // Date: 10-11-2012 4:34:17 PM --> wrong

Here is the MSDN doc for custom DateTime format strings.

Any ideas on what am I doing wrong? How can I achieve my desired result?

Edit:
The thing that is incorrect in the last line of sample code is that there is hyphens instead of slashes and I don’t know why.

Also, my computer’s language is set to English (Canada). But neither my “short” nor “long” date format look like M-d-yyyy so I have no idea where that is coming from.

  • 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-12T16:18:42+00:00Added an answer on June 12, 2026 at 4:18 pm

    / is the date separator, that is culture-dependant – in your current culture it is defined as -. If you want always a / use:

    Console.WriteLine("Date: " + datetime.ToString("M\"/\"d\"/\"yyyy h:m:ss tt"));
    

    or

    Console.WriteLine("Date: " + datetime.ToString("M'/'d'/'yyyy h:m:ss tt"));
    

    i.e. put the parts that you want to be output ‘as is’ inside quotes.

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

Sidebar

Related Questions

I have the following date in string format 2011-29-01 12:00 am . Now I
I have the following string TheTimeFormat as the custom time format: {0:h:mm tt} I
I am trying to convert a string into date time format. DateTime.Parse(tempfrmBankDetails.dgvBankDetails.SelectedRows[0].Cells[PaymentDate].Value.ToString(),null); This is
I have a std::string such as 20040531 , I want to format this as
I can't get my custom DateTime string format to work in my binding. I
I have a string representing date (mysql database DateTime) i want to convert it
I have a list of custom objects. These objects have 2 datetime properties on
I have custom UITableViewCell . It contains UITextLabel . When I press this cell
I have custom validation rule: public function customRule($check) { } Inside this rule I
I have a webform with two custom validators: One to validate that a string

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.