By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,376 Members | 1,581 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,376 IT Pros & Developers. It's quick & easy.

Day from Datetimepicker

P: n/a
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
Share this Question
Share on Google+
13 Replies


P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a

"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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a

"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

P: n/a

"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

P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.