Solved

Format output from a date time picker

Posted on 2007-12-02
6
1,577 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
  • 3
  • 2
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
this.textBox1.Text = this.dateTimePicker1.Value.ToString();
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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
Comment Utility
Fine job
angelIII thank you very much for your time and attention
John
0
 

Expert Comment

by:haggard
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now