1

I'm having some problems on putting my DateTime into a string when I try to put a "/" on the date on the output it does a tab instead of putting the "/"

changeDate_temp = calendarPostPone.SelectedDate.Value.ToString("dd/MM/yyyy").Split(' ');

        showDate = new DateTime(Convert.ToInt32(changeDate_temp[2].Trim()), 
            Convert.ToInt32(changeDate_temp[1].Trim()), 
            Convert.ToInt32(changeDate_temp[0].Trim()),
            12, 0, 0);

        Console.WriteLine(showDate.ToString("dd/MM/yyyy | HH:mm"));

Output of the code:

All the code works just not the "Console.WriteLine(showDate.ToString("dd/MM/yyyy | HH:mm"));" at least the way I want it to work..

bagaco
  • 25
  • 7
  • 1
    i am not able to reproduce this issue, which culture you are using on your machine ? – Ehsan Sajjad Apr 02 '23 at 00:13
  • What is the goal of `ToString` and/or `Split(' ')` in `changeDate_temp = calendarPostPone.SelectedDate.Value.ToString("dd/MM/yyyy").Split(' ');`? Also was not able to repro, works just fine for me - [fiddle](https://dotnetfiddle.net/nSwoyx), the same output I get in console. What culture is used on your machine? Also what console settings do you have? – Guru Stron Apr 02 '23 at 00:18

1 Answers1

2

The slash will be replaced with the date separator of the current culture.

To force the use of slashes, enclose them in single quotes.

Console.WriteLine(showDate.ToString("dd'/'MM'/'yyyy | HH:mm"));
NineBerry
  • 26,306
  • 3
  • 62
  • 93