Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Format output from a date time picker

Posted on 2007-12-02
6
Medium Priority
?
1,585 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

597 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