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. Dates

Dates

Scheduled Pinned Locked Moved C#
helptutorialquestion
4 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.
  • S Offline
    S Offline
    scotlandc
    wrote on last edited by
    #1

    Hi, I am trying to set the value of a DateTimePicker to the first of next month in a UK date format. ie every day this month (March) the DTP will read 01/04/2005 then next month it will read 01/05/2004. Anyone know how it can be done? I've sorted the month part out with AddMonth(1) but have no idea how to set the date to 01 each time? Please can someone help? Thanks in advance Scott

    T S 2 Replies Last reply
    0
    • S scotlandc

      Hi, I am trying to set the value of a DateTimePicker to the first of next month in a UK date format. ie every day this month (March) the DTP will read 01/04/2005 then next month it will read 01/05/2004. Anyone know how it can be done? I've sorted the month part out with AddMonth(1) but have no idea how to set the date to 01 each time? Please can someone help? Thanks in advance Scott

      T Offline
      T Offline
      techieboi
      wrote on last edited by
      #2

      Alright mate, not sure I understand your problem but hopefully the code below will help. DateTime startOfMonth = DateTime.Now.AddMonths(1); startOfMonth = startOfMonth.AddDays(-startOfMonth.Day + 1); The code add's one month to the current date and then defaults the date to the 1st of the month.

      H 1 Reply Last reply
      0
      • T techieboi

        Alright mate, not sure I understand your problem but hopefully the code below will help. DateTime startOfMonth = DateTime.Now.AddMonths(1); startOfMonth = startOfMonth.AddDays(-startOfMonth.Day + 1); The code add's one month to the current date and then defaults the date to the 1st of the month.

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        Do keep in mind that the DateTime type always uses the Gregorian calendar, so you should use the Calendar class to truly get the right date if not doing this strickly for the DateTimePicker. See http://blogs.msdn.com/michkap/archive/2005/03/28/402839.aspx[^] for more information. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

        1 Reply Last reply
        0
        • S scotlandc

          Hi, I am trying to set the value of a DateTimePicker to the first of next month in a UK date format. ie every day this month (March) the DTP will read 01/04/2005 then next month it will read 01/05/2004. Anyone know how it can be done? I've sorted the month part out with AddMonth(1) but have no idea how to set the date to 01 each time? Please can someone help? Thanks in advance Scott

          S Offline
          S Offline
          scotlandc
          wrote on last edited by
          #4

          Thanks for replying folks, much appreciated. The code works perfectly, thank you. I will bear that in mind about the Gregorian Calendar too, thanks for pointing it out. Again, much appreciated. Scott ;)

          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