Day from Datetimepicker

J

John

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
 
J

John

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
 
J

John

Steve Gerrard said:
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!
 
M

Martin H.

Hello John,



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
 
J

John

Martin H. said:
Hello John,






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
 
J

John

John said:
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
 
I

intiratr

Try set you app. culture to france when app. start then

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

John

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

Debug.Print(WeekdayName(Weekday(DateTimePicker1.Value, 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
 
J

John

John said:
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.
 
J

John

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
 
J

John

Steve Gerrard said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DateTimePicker 1
DateTimePick Question 5
DateTimePicker Control bug? 4
changing culture on datetimepicker 2
DateTimePicker : request for CulturInfo 3
Query from day of week 3
day names 4
Day formula 4

Top