473,378 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

DateTimePicker Date Format Weirdness

I have a DateTimePicker control on my form that is displaying the date
format in UK format (dd/mm/yy).

However, in my code dtpStartDate.Value gives a date in US format, but
dtpStartDate.Value.ToString() gives the date in the required UK format!

Any ideas? All system locale settings are set to British/UK settings.
Nov 15 '05 #1
9 5017
Ed Crowley <cu******@pacbell.net> wrote:
I have a DateTimePicker control on my form that is displaying the date
format in UK format (dd/mm/yy).

However, in my code dtpStartDate.Value gives a date in US format, but
dtpStartDate.Value.ToString() gives the date in the required UK format!

Any ideas? All system locale settings are set to British/UK settings.


DateTimePicker.Value isn't in *any* particular format - it's just a
DateTime. What do you mean by "gives a date in US format"?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Ed Crowley <cu******@pacbell.net> wrote:
I have a DateTimePicker control on my form that is displaying the date
format in UK format (dd/mm/yy).

However, in my code dtpStartDate.Value gives a date in US format, but
dtpStartDate.Value.ToString() gives the date in the required UK format!

Any ideas? All system locale settings are set to British/UK settings.


DateTimePicker.Value isn't in *any* particular format - it's just a
DateTime. What do you mean by "gives a date in US format"?


When I assign the value of the DateTimePicker to a DateTime variable, it is
in US format (dd/mm/yy) when I step through the code. When I then try and
pass this date as a parameter to a SQL Server stored procedure it falls over
as the date is invalid (for example today is 11/25/2003 which isn't a valid
UK date, but 11/11/2003 works fine).
Nov 15 '05 #3
My guess is that Visual Studio's internal workings are showing through,
and Visual Studio follows US formats, not international or standard ones..
(For instance week enumeration starts with sunday, despite that standards
clearly state monday to be first day of a week)

Are you getting US formats when outputting result somewhere, or only while
debugging?
As mentioned by Jon, Value returns a DateTime object which can be any
format but itself should be local independent.
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
I don't think you can change the way the DateTime object stores it's date
which is as mm/dd/yyyy
I'm not sure how SQL accepts a datetime object, but you may have to change
the sql procedure to perceive that datetime object as mm/dd/yyyy or pass
it something other than a DateTime object. I could be wrong.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #5
Ed Crowley <cu******@pacbell.net> wrote:
DateTimePicker.Value isn't in *any* particular format - it's just a
DateTime. What do you mean by "gives a date in US format"?
When I assign the value of the DateTimePicker to a DateTime variable, it is
in US format (dd/mm/yy) when I step through the code.


That's just how the debugger happens to show it, I suspect. DateTimes
themselves have no intrinsic format.
When I then try and
pass this date as a parameter to a SQL Server stored procedure it falls over
as the date is invalid (for example today is 11/25/2003 which isn't a valid
UK date, but 11/11/2003 works fine).


How are you passing the date? If you specify it as a DateTime rather
than converting it into a string in the first place, it should be fine.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
Morten Wennevik <Mo************@hotmail.com> wrote:
I don't think you can change the way the DateTime object stores it's date
which is as mm/dd/yyyy


No, DateTime stores it as a long.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7
On Tue, 25 Nov 2003 12:57:07 +0100, Morten Wennevik <Mo************@hotmail.com>
wrote:
My guess is that Visual Studio's internal workings are showing through,
and Visual Studio follows US formats, not international or standard ones.
(For instance week enumeration starts with sunday, despite that standards
clearly state monday to be first day of a week)


Yes. This can be changed by updating the culture.FirstDayOfWeek, but even then,
the built-in DateTimePicker and MonthCalendar do not respect the settings of the
current culture. Go figure.

Nov 15 '05 #8
On Tue, 25 Nov 2003 11:43:15 -0000, "Ed Crowley" <cu******@pacbell.net> wrote:
When I assign the value of the DateTimePicker to a DateTime variable, it is
in US format (dd/mm/yy) when I step through the code. When I then try and

U.S. format is mm/dd/yy

Nov 15 '05 #9

"Kerry Sanders" <di****@NOSPAMyahoo.com> wrote in message
news:i7********************************@4ax.com...
On Tue, 25 Nov 2003 11:43:15 -0000, "Ed Crowley" <cu******@pacbell.net> wrote:
When I assign the value of the DateTimePicker to a DateTime variable, it isin US format (dd/mm/yy) when I step through the code. When I then try
and

U.S. format is mm/dd/yy


I know ... it was a typo!
Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: E-Cube | last post by:
Hello All, I have a datetimepicker whose initial format is: DateTimePicker1.Format = DateTimePickerFormat.Custom DateTimePicker1.CustomFormat = " " DateTimePicker1.Checked = False which will...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
7
by: Edward Mitchell | last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the controls by dragging the DateTime picker from...
2
by: Chris Fairman | last post by:
NG, Maybe I'm missing a key step, but it seems when typing dates into a DateTimePicker control (format = 'Short'), the controls' .text property is not updated until the control losses focus. ...
2
by: Claes Wedin | last post by:
My customer needs a DateTimePicker in VS2005 C# that can show emty date values (blank/space/null). I need a control that: 1. Can show a blank value 2. Detete a date when hitting the delete...
5
by: Terry | last post by:
My system short date format is dd/mm/yy. The DateTimePicker returns mm/dd/yyyy hh:mm:ss PM. I need to get this value formated into dd/mm/yyyy regardless of the system short date format, what...
0
by: tschroeder250 | last post by:
Hi Everyone, There are so many Nullable DateTimePickers out there that this post may not even be found among all the others, but I wanted to try. First, I want to thank all the authors of the...
11
by: jessy | last post by:
Hi, I have a problem with my DateTimePicker javascript code which i downloaded , the problem is when i pick the date and the date appears in my Text Field and i click Submit the date which i picked...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.