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?
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");
You can easily format the datetime into a string like the one you want:
the_date_time.ToString("yyyyMMdd");
Post format your date:
string formattedDate = MyDateTime.ToString("yyyyMMdd")
if directly from the DateTimePicker control use:
string formattedDate = MyDateTime.Value.ToString("yyyyMMdd")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With