Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set DateTimePicker Control to format YYYYMMDD?

I am putting together a simple C# Windows Forms Application. I am setting my DateTimePicker control on load to the current DateTime, example "11/12/2013 9:49:49 AM". I then use this value in a query to my 400 system, but I am getting an error because the field I query against the DateTimePicker Controls value is in format 'YYYYMMDD'.

How do I format the value of my DateTimePicker Control to 'YYYYMMDD' to use it in my query?

like image 400
Analytic Lunatic Avatar asked Nov 12 '13 16:11

Analytic Lunatic


3 Answers

Actually, if your control is named dtpDate, you should use something like this (using the Value property of the control):

string selectDateAsString = dtpDate.Value.ToString("yyyyMMdd");
like image 77
Yannick Blondeau Avatar answered Sep 19 '22 11:09

Yannick Blondeau


You can easily format the datetime into a string like the one you want:

 the_date_time.ToString("yyyyMMdd");
like image 25
Tobberoth Avatar answered Sep 20 '22 11:09

Tobberoth


Post format your date:

string formattedDate = MyDateTime.ToString("yyyyMMdd")

if directly from the DateTimePicker control use:

string formattedDate = MyDateTime.Value.ToString("yyyyMMdd")

like image 21
InContext Avatar answered Sep 22 '22 11:09

InContext