Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling ToString("YYYY-mm-dd") results in wrong date format

I've got a constructor which takes a DateTime object:

public Report(DateTime date, string start = "0", string end = "0")
{
    Logger.Info("Creating a new Report...");

    StartTime = start;
    EndTime = end;
    Date = date.ToString("YYYY-mm-dd");

    SetStartEndTimes();

    Logger.Info("Report Created");
}

Now, this was working fine just 3 days ago. However, I come back today, after a break, and this is the results I'm seeing:

enter image description here

As you can see, the date being passed in is right. However, after the format, it is not. Again, this worked before my break. I come back, and I get this. Am I missing something? Why would it format so incorrectly after working since the beginning?

EDIT

Thanks guys. The messed up part is looking through the source control at previous versions, this worked. Or maybe I imagined it working. I don't know. But it's been this way for about 3 months.

like image 953
PiousVenom Avatar asked Apr 19 '13 13:04

PiousVenom


People also ask

How do I change the date format in ToString?

To do this, you use the "MM/yyyy" format string. The format string uses the current culture's date separator. Getting a string that contains the date and time in a specific format. For example, the "MM/dd/yyyyHH:mm" format string displays the date and time string in a fixed format such as "19//03//2013 18:06".

What is the default DateTime format in c#?

DateTimeFormat. ShortDatePattern = "MM/dd/yyyy"; app.

What is FFF in date format?

The "fff" custom format specifier represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.


1 Answers

Year must be lowercase and month uppercase:

Date = date.ToString("yyyy-MM-dd");  // btw, lowercase mm means minutes

Custom Date and Time Format Strings

like image 123
Tim Schmelter Avatar answered Sep 18 '22 14:09

Tim Schmelter