Format DateTime to specific format

When this function is called, it creates a text file with these attributes. There is one attribute known as start_date. When I convert to DateTime, the date format will be MM:DD:YYYY and an error will be shown. I am not sure how to change the format to DD:MM:YYYY, I have also read on the DateTime formatting but I still do not understand. Thanks.

Code is as follows:

static void generateInfoForITDepartment()
    string filepath = @"C:\Users\notgivingmydirectory\HRMasterlist.txt";
    List<Employee> people = new List<Employee>();
    List<string> lines = File.ReadAllLines(filepath).ToList();
    foreach (var line in lines)
        string[] entries = line.Split('|');

        Employee newIT = new Employee();

        newIT.Nric = entries[0];
        newIT.FullName = entries[1];
        newIT.Start_Date = Convert.ToDateTime(entries[3]);
        newIT.Department = entries[5];
        newIT.MobileNo = entries[6];

    List<string> output = new List<string>();
    foreach (var it in people)
        output.Add($"{ it.Nric }, { it.FullName }, { it.Start_Date }, { it.Department }, { it.MobileNo }");
    File.WriteAllLines("ITDepartment.txt", output);
    Console.WriteLine("ITDepartment.txt has been created");

Read more here:

Content Attribution

This content was originally published by user15930341 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: