Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. days of week

days of week

Scheduled Pinned Locked Moved C#
csharpmcpquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tauseef A
    wrote on last edited by
    #1

    hi guys i want to get first and last date of week given by a week number and year is there any way ? regards.

    Tauseef A Khan MCP Dotnet framework 2.0.

    S L 2 Replies Last reply
    0
    • T Tauseef A

      hi guys i want to get first and last date of week given by a week number and year is there any way ? regards.

      Tauseef A Khan MCP Dotnet framework 2.0.

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      Have a look at this: http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^] You can use various datetime properties available to get what you want.

      1 Reply Last reply
      0
      • T Tauseef A

        hi guys i want to get first and last date of week given by a week number and year is there any way ? regards.

        Tauseef A Khan MCP Dotnet framework 2.0.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Following is the code for retrieving first and last day of the given date. You need to give date instead of just year and week no. In following code I have also counted sunday as one of the week day. You can omit sunday in switch case. DateTime dt; dt = DateTime.Today; DateTime date = DateTime.Now; System.Globalization.CultureInfo cult_info = System.Globalization.CultureInfo.CreateSpecificCulture("no"); System.Globalization.Calendar cal = cult_info.Calendar; int weekNo = cal.GetWeekOfYear(dt, cult_info.DateTimeFormat.CalendarWeekRule, cult_info.DateTimeFormat.FirstDayOfWeek); MessageBox.Show(weekNo.ToString()); int plus1 = 0; int minus1 = 0; switch (date.DayOfWeek) { case DayOfWeek.Monday: plus1 = 6; minus1 = 0; break; case DayOfWeek.Tuesday: plus1 = 5; minus1 = 1; break; case DayOfWeek.Wednesday: plus1 = 4; minus1 = 2; break; case DayOfWeek.Thursday: plus1 = 3; minus1 = 3; break; case DayOfWeek.Friday: plus1 = 2; minus1 = 4; break; case DayOfWeek.Saturday: plus1 = 1; minus1 = 5; break; case DayOfWeek.Sunday: plus1 = 0; minus1 = 6; break; } MessageBox.Show(date.AddDays(-minus1).ToShortDateString()); MessageBox.Show(date.AddDays(plus1).ToShortDateString());

        Jinal Desai

        L 1 Reply Last reply
        0
        • L Lost User

          Following is the code for retrieving first and last day of the given date. You need to give date instead of just year and week no. In following code I have also counted sunday as one of the week day. You can omit sunday in switch case. DateTime dt; dt = DateTime.Today; DateTime date = DateTime.Now; System.Globalization.CultureInfo cult_info = System.Globalization.CultureInfo.CreateSpecificCulture("no"); System.Globalization.Calendar cal = cult_info.Calendar; int weekNo = cal.GetWeekOfYear(dt, cult_info.DateTimeFormat.CalendarWeekRule, cult_info.DateTimeFormat.FirstDayOfWeek); MessageBox.Show(weekNo.ToString()); int plus1 = 0; int minus1 = 0; switch (date.DayOfWeek) { case DayOfWeek.Monday: plus1 = 6; minus1 = 0; break; case DayOfWeek.Tuesday: plus1 = 5; minus1 = 1; break; case DayOfWeek.Wednesday: plus1 = 4; minus1 = 2; break; case DayOfWeek.Thursday: plus1 = 3; minus1 = 3; break; case DayOfWeek.Friday: plus1 = 2; minus1 = 4; break; case DayOfWeek.Saturday: plus1 = 1; minus1 = 5; break; case DayOfWeek.Sunday: plus1 = 0; minus1 = 6; break; } MessageBox.Show(date.AddDays(-minus1).ToShortDateString()); MessageBox.Show(date.AddDays(plus1).ToShortDateString());

          Jinal Desai

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Why not just use the numeric values of the days? See here[^] for some hints about using these values.

          It's time for a new signature.

          L T 2 Replies Last reply
          0
          • L Lost User

            Why not just use the numeric values of the days? See here[^] for some hints about using these values.

            It's time for a new signature.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            ya we can do in that way also. I am just interested in solution. (However it is not optimized solution)

            Jinal Desai

            L 1 Reply Last reply
            0
            • L Lost User

              ya we can do in that way also. I am just interested in solution. (However it is not optimized solution)

              Jinal Desai

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Jinal Desai - LIVE wrote:

              However it is not optimized solution

              Quite the reverse! ;)

              It's time for a new signature.

              L 1 Reply Last reply
              0
              • L Lost User

                Why not just use the numeric values of the days? See here[^] for some hints about using these values.

                It's time for a new signature.

                T Offline
                T Offline
                Tauseef A
                wrote on last edited by
                #7

                what you mean ?

                Tauseef A Khan MCP Dotnet framework 2.0.

                L 1 Reply Last reply
                0
                • T Tauseef A

                  what you mean ?

                  Tauseef A Khan MCP Dotnet framework 2.0.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Tauseef A wrote:

                  what you mean ?

                  Look at the documentation for the DateTime class and also some of the extra information in the link provided by Luc Pattyn.

                  It's time for a new signature.

                  1 Reply Last reply
                  0
                  • L Lost User

                    Jinal Desai - LIVE wrote:

                    However it is not optimized solution

                    Quite the reverse! ;)

                    It's time for a new signature.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    I have just calculated based on particular date. It is not just calculating first day of year. So I code accordingly. Hope you understand! :)

                    Jinal Desai - LIVE

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups