?
Solved

Format output from a date time picker

Posted on 2007-12-02
6
Medium Priority
?
1,584 Views
Last Modified: 2013-12-16
Is there a method for formatting output from a date time picker using the following code
this.textBox1.Text = this.dateTimePicker1.ToString();
I get
System.Windows.Forms.DateTimePicker, Value: 21/11/2007 20:40:07
in the textbox. It would make life easier if it didn't come with the leading string
(Is it possible to select the day, month or year as separate integers (this would be useful for applications that would run predictably in the UK and US)
0
Comment
Question by:johnecollins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20392305
this.textBox1.Text = this.dateTimePicker1.Value.ToString();
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20392309
note: the .Value is what return the datetime data typed value, and you can "extract" from that the .Year, .Month, .Day
0
 

Author Comment

by:johnecollins
ID: 20392390
angelIII
Thanks for this as you will know already it gave a 'clean' string of the data and time
so for 25th December 2007 I get 25/12/2007 21:18:10 instantly better!
I can then substring the day, month and year
This is a little worrying as in the UK and probably many other places in the world the format of dates is
dd/mm/yyyy
Whereas in the US its mm/dd/yyyy should I refer to 'region'  so that I can determien where the month is?
If that is what is reccomended how do I do it?

Thank you very much

John
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 20392410
please read my second comment:



this.dateTimePicker1.Value.Year
this.dateTimePicker1.Value.Month
this.dateTimePicker1.Value.Day

Open in new window

0
 

Author Closing Comment

by:johnecollins
ID: 31412217
Fine job
angelIII thank you very much for your time and attention
John
0
 

Expert Comment

by:haggard
ID: 20662564
Close, but there's a way to get your date time string formated without going through the process of extracting specific values. The DateTime ToString accepts either a format string or a format string plus a culture specification. If no culture is specified then the date time is displayed in a fashion appropraite for the current application culture. The format string allows specification in an abbreviated or an explicit fashion. For example, date.ToString("d") displays in (for US) M/D/YYYY format. Look here for details on standard datetime formatting.

http://msdn2.microsoft.com/en-us/library/az4se3k1.aspx

Custom formatting gives complete control over everything and here's a link to the details.

http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx

==
Richard Lewis Haggard
Haggard-And-Associates.com
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question