Day from Datetimepicker

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    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(Dat eTimePicker1.Va lue.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

  • John

    #2
    Re: Day from Datetimepicker

    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

    Comment

    • Steve Gerrard

      #3
      Re: Day from Datetimepicker

      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(Dat eTimePicker1.Va lue.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("dd dd")


      Comment

      • John

        #4
        Re: Day from Datetimepicker


        "Steve Gerrard" <mynamehere@com cast.netwrote in message
        news:qtydnQnOK-D3ucTVnZ2dnUVZ_ hGdnZ2d@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(Da teTimePicker1.V alue.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("dd dd")
        >
        >
        Well the datetimepicker1 says Wednesday June 18 2008 and the above code for
        it produces:

        Thursday - which is not correct!

        Comment

        • Martin H.

          #5
          Re: Day from Datetimepicker

          Hello John,



          On 18.06.2008 23:25, wrote John:
          >>WeekdayName(D ateTimePicker1. Value.DayOfWeek + 1) does not work if you
          >I would just try
          >DateTimePicker 1.Value.AddDays (1).ToString("d ddd")
          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.DayOfWee k.ToString

          * DateTimePicker1 .Value.ToString ("dddd")

          * Format(DateTime Picker1.Value," dddd")

          Best regards,

          Martin

          Comment

          • John

            #6
            Re: Day from Datetimepicker


            "Martin H." <hkshk@gmx.netw rote in message news:48592c1a@1 27.0.0.1...
            Hello John,
            >
            >
            >
            On 18.06.2008 23:25, wrote John:
            >>>WeekdayName( DateTimePicker1 .Value.DayOfWee k + 1) does not work if you
            >
            >>I would just try
            >>DateTimePicke r1.Value.AddDay s(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.DayOfWee k.ToString
            >
            * DateTimePicker1 .Value.ToString ("dddd")
            >
            * Format(DateTime Picker1.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 datetimepickerc ontrol 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

            Comment

            • John

              #7
              Re: Day from Datetimepicker


              "John" <no-email-supplied@nothin g.comwrote in message
              news:eSPDz4V0IH A.5516@TK2MSFTN GP02.phx.gbl...
              >
              "Martin H." <hkshk@gmx.netw rote in message news:48592c1a@1 27.0.0.1...
              >Hello John,
              >>
              >>
              >>
              >On 18.06.2008 23:25, wrote John:
              >>>>WeekdayName (DateTimePicker 1.Value.DayOfWe ek + 1) does not work if you
              >>
              >>>I would just try
              >>>DateTimePick er1.Value.AddDa ys(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.DayOfWee k.ToString
              >>
              >* DateTimePicker1 .Value.ToString ("dddd")
              >>
              >* Format(DateTime Picker1.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 datetimepickerc ontrol 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(Wee kday(DateTimePi cker1.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


              Comment

              • =?Utf-8?B?aW50aXJhdHI=?=

                #8
                Re: Day from Datetimepicker

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

                System.Threadin g.Thread.Curren tThread.Current Culture = new
                System.Globaliz ation.CultureIn fo("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
                >
                >

                Comment

                • Steve Gerrard

                  #9
                  Re: Day from Datetimepicker

                  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(Wee kday(DateTimePi cker1.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(Wee kdayName(Weekda y(DateTimePicke r1.Value, 0), 0, 0))

                  Debug.Print(Dat eTimePicker1.Va lue.ToString("d ddd"))



                  Comment

                  • John

                    #10
                    Re: Day from Datetimepicker


                    "Steve Gerrard" <mynamehere@com cast.netwrote in message
                    news:VZudndrEb-Hu9MfVnZ2dnUVZ_ gWdnZ2d@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(Wee kday(DateTimePi cker1.Value, 0), 0, 0)
                    >>
                    >This will always return the correct local setting day name from the
                    >datetimepick er
                    >>
                    >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(Wee kdayName(Weekda y(DateTimePicke r1.Value, 0), 0, 0))
                    >
                    Debug.Print(Dat eTimePicker1.Va lue.ToString("d ddd"))
                    >
                    >
                    >
                    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

                    Comment

                    • John

                      #11
                      Re: Day from Datetimepicker


                      "John" <no-email-supplied@nothin g.comwrote in message
                      news:%23UaBglh0 IHA.5728@TK2MSF TNGP06.phx.gbl. ..
                      >
                      "Steve Gerrard" <mynamehere@com cast.netwrote in message
                      news:VZudndrEb-Hu9MfVnZ2dnUVZ_ gWdnZ2d@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(Wee kday(DateTimePi cker1.Value, 0), 0, 0)
                      >>>
                      >>This will always return the correct local setting day name from the
                      >>datetimepicke r
                      >>>
                      >>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(We ekdayName(Weekd ay(DateTimePick er1.Value, 0), 0, 0))
                      >>
                      >Debug.Print(Da teTimePicker1.V alue.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.

                      Comment

                      • John

                        #12
                        Re: Day from Datetimepicker


                        "John" <no-email-supplied@nothin g.comwrote in message
                        news:e2cDirh0IH A.3884@TK2MSFTN GP05.phx.gbl...
                        >
                        "John" <no-email-supplied@nothin g.comwrote in message
                        news:%23UaBglh0 IHA.5728@TK2MSF TNGP06.phx.gbl. ..
                        >>
                        >"Steve Gerrard" <mynamehere@com cast.netwrote in message
                        >news:VZudndr Eb-Hu9MfVnZ2dnUVZ_ gWdnZ2d@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

                        Comment

                        • Steve Gerrard

                          #13
                          Re: Day from Datetimepicker

                          John wrote:
                          "John" <no-email-supplied@nothin g.comwrote in message
                          news:e2cDirh0IH A.3884@TK2MSFTN GP05.phx.gbl...
                          >>
                          >"John" <no-email-supplied@nothin g.comwrote in message
                          >news:%23UaBglh 0IHA.5728@TK2MS FTNGP06.phx.gbl ...
                          >>>
                          >>"Steve Gerrard" <mynamehere@com cast.netwrote in message
                          >>news:VZudndrE b-Hu9MfVnZ2dnUVZ_ gWdnZ2d@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
                          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. :)


                          Comment

                          • John

                            #14
                            Re: Day from Datetimepicker


                            "Steve Gerrard" <mynamehere@com cast.netwrote in message
                            news:ibGdnbaSO5 Gg5cfVnZ2dnUVZ_ oninZ2d@comcast .com...
                            John wrote:
                            >"John" <no-email-supplied@nothin g.comwrote in message
                            >news:e2cDirh0I HA.3884@TK2MSFT NGP05.phx.gbl.. .
                            >>>
                            >>"John" <no-email-supplied@nothin g.comwrote in message
                            >>news:%23UaBgl h0IHA.5728@TK2M SFTNGP06.phx.gb l...
                            >>>>
                            >>>"Steve Gerrard" <mynamehere@com cast.netwrote in message
                            >>>news:VZudndr Eb-Hu9MfVnZ2dnUVZ_ gWdnZ2d@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
                            >
                            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

                            Comment

                            Working...