Set specific date with string to dateTimePicker

10,147

You can use DateTime.ParseExact to parse date string in the format which you have:

dateTimePicker.Value = 
  DateTime.ParseExact("25/03/2017", "dd/MM/yyyy", CultureInfo.InvariantCulture);

Note that when you are getting date from DateTimePicker control you are converting same date to another format, and it will look like 2017-3-25.

Share:
10,147
nikorio
Author by

nikorio

Updated on June 05, 2022

Comments

  • nikorio
    nikorio almost 2 years

    I'm trying to set specific date for dateTimePicker, but not sure how to do it properly. The goal is to load date and time of user previous load insert from text document, each time user loads applications, and then to save new date as string for next using to load into dateTimePicker.

    This way it does not sets and I'm not sure how to load string like "25/03/2017" to:

       dateTimePicker.Value = new DateTime(1978, 05, 22);
    

    to use it as string for further processing:

       string bd = dateTimePicker.Value.ToString("yyyy-M-d");