Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set specific date with string to dateTimePicker

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");  
like image 244
nikorio Avatar asked Jun 19 '26 08:06

nikorio


1 Answers

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.

like image 147
Sergey Berezovskiy Avatar answered Jun 20 '26 22:06

Sergey Berezovskiy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!