473,394 Members | 1,640 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,394 software developers and data experts.

Day from Datetimepicker

Hi

I have a simple requirement but finding it very difficult to implement
correctly.

I have a datetimepicker, all what i want to do is simply to get the string
day name of the selected date, for example, Thursday.

WeekdayName(DateTimePicker1.Value.DayOfWeek + 1) does not work if you set
the default country to say France on your pc as the day that is returned is
one day off. It obviuosly has something to do with the first day of the
week, but i don't know how to fit it all together so it works correctly
whatever country you set your pc to in the regional settings

Jun 27 '08 #1
13 10629
Just to add - i need the day name in the appropriate language, so if the
date is 18th June 2008 then it will return Wednesday (for english settings)
and for example mercredi for a france setting

Jun 27 '08 #2
John wrote:
Hi

I have a simple requirement but finding it very difficult to implement
correctly.

I have a datetimepicker, all what i want to do is simply to get the
string day name of the selected date, for example, Thursday.

WeekdayName(DateTimePicker1.Value.DayOfWeek + 1) does not work if you
set the default country to say France on your pc as the day that is
returned is one day off. It obviuosly has something to do with the
first day of the week, but i don't know how to fit it all together so
it works correctly whatever country you set your pc to in the
regional settings
I would just try
DateTimePicker1.Value.AddDays(1).ToString("dddd")
Jun 27 '08 #3

"Steve Gerrard" <my********@comcast.netwrote in message
news:qt******************************@comcast.com. ..
John wrote:
>Hi

I have a simple requirement but finding it very difficult to implement
correctly.

I have a datetimepicker, all what i want to do is simply to get the
string day name of the selected date, for example, Thursday.

WeekdayName(DateTimePicker1.Value.DayOfWeek + 1) does not work if you
set the default country to say France on your pc as the day that is
returned is one day off. It obviuosly has something to do with the
first day of the week, but i don't know how to fit it all together so
it works correctly whatever country you set your pc to in the
regional settings

I would just try
DateTimePicker1.Value.AddDays(1).ToString("dddd")

Well the datetimepicker1 says Wednesday June 18 2008 and the above code for
it produces:

Thursday - which is not correct!

Jun 27 '08 #4
Hello John,

On 18.06.2008 23:25, wrote John:
>>WeekdayName(DateTimePicker1.Value.DayOfWeek + 1) does not work if you
>I would just try
DateTimePicker1.Value.AddDays(1).ToString("dddd ")
Well the datetimepicker1 says Wednesday June 18 2008 and the above code
for it produces:

Thursday - which is not correct!
It is correct as you add one day. So the ToString function will use the
date of June 19, which is a Thursday.

To get the weekday of the selected date you can use several methods.

* DateTimePicker1.Value.DayOfWeek.ToString

* DateTimePicker1.Value.ToString("dddd")

* Format(DateTimePicker1.Value,"dddd")

Best regards,

Martin
Jun 27 '08 #5

"Martin H." <hk***@gmx.netwrote in message news:48******@127.0.0.1...
Hello John,

On 18.06.2008 23:25, wrote John:
>>>WeekdayName(DateTimePicker1.Value.DayOfWeek + 1) does not work if you
>>I would just try
DateTimePicker1.Value.AddDays(1).ToString("dddd" )
>Well the datetimepicker1 says Wednesday June 18 2008 and the above code
for it produces:

Thursday - which is not correct!

It is correct as you add one day. So the ToString function will use the
date of June 19, which is a Thursday.

To get the weekday of the selected date you can use several methods.

* DateTimePicker1.Value.DayOfWeek.ToString

* DateTimePicker1.Value.ToString("dddd")

* Format(DateTimePicker1.Value,"dddd")

Best regards,

Martin
Hi Martin

I have used the above - it works fine when the Formats and Region in the
Control Panel are set to uk or usa, but if you set them to France then it
does not work the wrong "day" is returned. I need a bit of code that can
read the local day name from the datetimepickercontrol whatever the user has
set for the Formats and Region in the Clock, Language and Region settings in
the Control panel - i can get what i need for the usa and uk but it does
work for a france setting, and vice versa

Jun 27 '08 #6

"John" <no***************@nothing.comwrote in message
news:eS**************@TK2MSFTNGP02.phx.gbl...
>
"Martin H." <hk***@gmx.netwrote in message news:48******@127.0.0.1...
>Hello John,

On 18.06.2008 23:25, wrote John:
>>>>WeekdayName(DateTimePicker1.Value.DayOfWeek + 1) does not work if you
>>>I would just try
DateTimePicker1.Value.AddDays(1).ToString("dddd ")
>>Well the datetimepicker1 says Wednesday June 18 2008 and the above code
for it produces:

Thursday - which is not correct!

It is correct as you add one day. So the ToString function will use the
date of June 19, which is a Thursday.

To get the weekday of the selected date you can use several methods.

* DateTimePicker1.Value.DayOfWeek.ToString

* DateTimePicker1.Value.ToString("dddd")

* Format(DateTimePicker1.Value,"dddd")

Best regards,

Martin

Hi Martin

I have used the above - it works fine when the Formats and Region in the
Control Panel are set to uk or usa, but if you set them to France then it
does not work the wrong "day" is returned. I need a bit of code that can
read the local day name from the datetimepickercontrol whatever the user
has set for the Formats and Region in the Clock, Language and Region
settings in the Control panel - i can get what i need for the usa and uk
but it does work for a france setting, and vice versa
OK I've solved it. The correct way to get the dayofweek name whatever the
local settings is:

dim sday as string
sday = WeekdayName(Weekday(DateTimePicker1.Value, 0), 0, 0)

This will always return the correct local setting day name from the
datetimepicker

Took a lot of work to sort that one out.... hope others find it useful as i
cannot believe i was the only one to encounter this problem
Jun 27 '08 #7
Try set you app. culture to france when app. start then

System.Threading.Thread.CurrentThread.CurrentCultu re = new
System.Globalization.CultureInfo("fr-FR");

"John" wrote:
Just to add - i need the day name in the appropriate language, so if the
date is 18th June 2008 then it will return Wednesday (for english settings)
and for example mercredi for a france setting

Jun 27 '08 #8
John wrote:
OK I've solved it. The correct way to get the dayofweek name whatever
the local settings is:

dim sday as string
sday = WeekdayName(Weekday(DateTimePicker1.Value, 0), 0, 0)

This will always return the correct local setting day name from the
datetimepicker

Took a lot of work to sort that one out.... hope others find it
useful as i cannot believe i was the only one to encounter this
problem
I get the same result with both of these lines, with US or France settings:

Debug.Print(WeekdayName(Weekday(DateTimePicker1.Va lue, 0), 0, 0))

Debug.Print(DateTimePicker1.Value.ToString("dddd") )

Jun 27 '08 #9

"Steve Gerrard" <my********@comcast.netwrote in message
news:VZ******************************@comcast.com. ..
John wrote:
>OK I've solved it. The correct way to get the dayofweek name whatever
the local settings is:

dim sday as string
sday = WeekdayName(Weekday(DateTimePicker1.Value, 0), 0, 0)

This will always return the correct local setting day name from the
datetimepicker

Took a lot of work to sort that one out.... hope others find it
useful as i cannot believe i was the only one to encounter this
problem

I get the same result with both of these lines, with US or France
settings:

Debug.Print(WeekdayName(Weekday(DateTimePicker1.Va lue, 0), 0, 0))

Debug.Print(DateTimePicker1.Value.ToString("dddd") )
That is very odd - because I don't, only the first one works for me. Just
out of interest did you run the program after you made the local settings
changes (ie close VB down COMPLETELY, change local settings, then run vb and
test ). I am using VB 2008 v9.030428.1 SP1Beta1 under 3.5 SPI Framework

Jun 27 '08 #10

"John" <no***************@nothing.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>
"Steve Gerrard" <my********@comcast.netwrote in message
news:VZ******************************@comcast.com. ..
>John wrote:
>>OK I've solved it. The correct way to get the dayofweek name whatever
the local settings is:

dim sday as string
sday = WeekdayName(Weekday(DateTimePicker1.Value, 0), 0, 0)

This will always return the correct local setting day name from the
datetimepicker

Took a lot of work to sort that one out.... hope others find it
useful as i cannot believe i was the only one to encounter this
problem

I get the same result with both of these lines, with US or France
settings:

Debug.Print(WeekdayName(Weekday(DateTimePicker1.V alue, 0), 0, 0))

Debug.Print(DateTimePicker1.Value.ToString("dddd" ))
That is very odd - because I don't, only the first one works for me. Just
out of interest did you run the program after you made the local settings
changes (ie close VB down COMPLETELY, change local settings, then run vb
and test ). I am using VB 2008 v9.030428.1 SP1Beta1 under 3.5 SPI
Framework
OK - but that was not what i required from my original post - what that one
does is to return the English dayname and not the French one - that is why i
exluded it and said it did not work.

Jun 27 '08 #11

"John" <no***************@nothing.comwrote in message
news:e2**************@TK2MSFTNGP05.phx.gbl...
>
"John" <no***************@nothing.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>
"Steve Gerrard" <my********@comcast.netwrote in message
news:VZ******************************@comcast.com ...
I have fallen in the trap that i advised you to watch out for regarding
closing down - you are absolutely correct both give the same result

Jun 27 '08 #12
John wrote:
"John" <no***************@nothing.comwrote in message
news:e2**************@TK2MSFTNGP05.phx.gbl...
>>
"John" <no***************@nothing.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>>
"Steve Gerrard" <my********@comcast.netwrote in message
news:VZ******************************@comcast.co m...

I have fallen in the trap that i advised you to watch out for
regarding closing down - you are absolutely correct both give the
same result
What I did notice is that I had to rebuild the project twice to get a region
setting change to "take". After the first one, the displayed day would switch in
the control, but the code would still report the previous language (both
versions of the code). Then if I rebuilt again, the code would produce the new
language as well. Probably the same as shut down /restart.

I think it is common to find that testing and debugging regional issues is a
pain, and that you have to be careful to be sure that the language change has
really taken place before you assess your results. Or get two computers. :)
Jun 27 '08 #13

"Steve Gerrard" <my********@comcast.netwrote in message
news:ib******************************@comcast.com. ..
John wrote:
>"John" <no***************@nothing.comwrote in message
news:e2**************@TK2MSFTNGP05.phx.gbl...
>>>
"John" <no***************@nothing.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl.. .

"Steve Gerrard" <my********@comcast.netwrote in message
news:VZ******************************@comcast.c om...

I have fallen in the trap that i advised you to watch out for
regarding closing down - you are absolutely correct both give the
same result

What I did notice is that I had to rebuild the project twice to get a
region setting change to "take". After the first one, the displayed day
would switch in the control, but the code would still report the previous
language (both versions of the code). Then if I rebuilt again, the code
would produce the new language as well. Probably the same as shut down
/restart.

I think it is common to find that testing and debugging regional issues is
a pain, and that you have to be careful to be sure that the language
change has really taken place before you assess your results. Or get two
computers. :)

Yes that seems certainly what was happening

Jun 27 '08 #14

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

Similar topics

2
by: Angelina | last post by:
Hi, I have got two DateTimePicker's on my form to accept a guest arrival date and departure date.what i want to acheieve is ensure that the DateTimePicker2 (departure) is always greater than...
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...
1
by: John Smith | last post by:
Hey folks, Got some strange behavior going on here. I have a datetimepicker with showcheckbox = true; If I set Checked=true and set the Text of the datetimepicker, then then the Checked...
0
by: ROG | last post by:
Hi all with help from postings on the web, i have a dateTimePicker in one of my columns in the datagrid. However, when i move in to this column using the arrow keys, it automatically pops up,...
0
by: Sumit | last post by:
Hi all, I have a datetimepicker on my windows form. When the user selects it i check whether the date entered is a Sunday or not & if its not a sunday i want that the control remains on the...
4
by: Jacek Jurkowski | last post by:
.... the minimum date of DateTimePicker is 1753-01-01. How to make DateTime to do not show nothing in its text if this date is the value? I have a form with a field LastLogonDate. If user hasn't...
7
by: Clamara | last post by:
When adding a new record from my form, I pre-set my DateTimePicker's value to System.DateTime.Today Since the "Today" value is used most of the time, the user doesn't need to select a date from...
3
by: Charlie | last post by:
In the top portion of the DateTimePicker, where the value of the date is displayed, how can I detect whether the month or day or year is currently focused, or, if ShowCheckBox = True, whether the...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
4
by: jehugaleahsa | last post by:
Hello: We were hoping to allow users to have DateTimePicker value null so that a unused date is stored on a Database. Does the control support this? I am pretty sure it doesn't. How would you...
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.