Set DateTimePicker Control to YYYYMMDD format?

I am building a simple C # application for Windows Forms. I set my DateTimePicker control when loading into the current DateTime, for example, " 12/11/2013 9:49:49 AM ". Then I use this value in a request to my 400 system, but I get an error because the field I requesting the DateTimePicker Controls value is in the format "YYYYMMDD".

How do I set the value of my DateTimePicker control to "YYYYMMDD" to use it in my request?

+4
source share
6 answers

Actually, if your control has a name dtpDate, you should use something like this (using the property Valueof the control):

string selectDateAsString = dtpDate.Value.ToString("yyyyMMdd");
+6
source

You can easily format datetime into a string such as you want:

 the_date_time.ToString("yyyyMMdd");
+1
source

DateTime , tostring() .

string formateddate = dtpDate.Value.ToString("yyyyMMdd");
+1

:

string formattedDate = MyDateTime.ToString("yyyyMMdd")

DateTimePicker:

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

+1
source

@Analytic Lunatic, please look here for the error you get. I think this will solve the problem you are facing.

0
source

It worked for me ...

string dt = dateTimePicker1.Value.ToString("yyyy/MM/dd");
0
source

All Articles