Solved

DateTimePicker with Custom Format: DateTimePickerFormat.Short + DateTimePickerFormat.Time?

Posted on 2008-10-15
4
1,836 Views
Last Modified: 2012-05-05
I have an application that is used worldwide. I use datetimepickers and the format needs to be <Short date> <Short Time>.
It doesn't appear that there is a way to do this. Using a custom format doesn't work because USA uses: MM/dd/yyy and many other countries use dd/MM/yyyy. I can't imagine that Microsoft wouldn't make a way to do this. What am I missing?
0
Comment
Question by:gcook17
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:apeter
ID: 22725031
The format strings can be combined to format the date and time. For example, to display the date and time as 06/15/2001 12:00 PM, this property should be set to "MM'/'dd'/'yyyy hh':'mm tt".

So add any other special characters in btw.

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"  'Another Formatter
0
 

Author Comment

by:gcook17
ID: 22725123
Thank you for your comment however I am aware of this: that you can combine the format strings. The problem with this is: With USA this format is fine: "MM'/'dd'/'yyyy hh':'mm tt" But with UK and many other countries the fomat must be "dd/MM/'yyyy hh':'mm tt. In VB6 yiu could concatenate "Short Date" & ' ' & "Short Time" to obtain the correct format regardless of the Regional Locale settings.
0
 
LVL 25

Accepted Solution

by:
apeter earned 500 total points
ID: 22725480
1. Get the date from the date picker.
2. Create a date object from above value.
3. DateTime has two methods, ToShortDateString and ToShortTimeString(). Concatenate them.

Dim instance As DateTime
Dim returnValue As String
Dim instance As New DateTime(year, month, day)
returnValue = instance.ToShortDateString()

0
 

Author Closing Comment

by:gcook17
ID: 31506465
Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

912 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

19 Experts available now in Live!

Get 1:1 Help Now