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. Visual Basic
  4. VB.NET Date Functions Calculations [modified] - SOLVED

VB.NET Date Functions Calculations [modified] - SOLVED

Scheduled Pinned Locked Moved Visual Basic
csharphelp
5 Posts 2 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.
  • U Offline
    U Offline
    User 4417354
    wrote on last edited by
    #1

    Hi I have DatePicker and the Maxdate is set to today: I am struggling with the MinDate. I need to set the Mindate to the 1st of 3 Months back(Keep in mind that the current month will be 3rd Month). Ex.1 For instance if we work it out as today the MinDate has to be: 01 January 2010 Ex.2 if today is the 16th of April 2010 the min date has to be: 01 Feb 2010 I hope someone can help me with this as I am really struggling with this calculation Thank you in advanced

    modified on Tuesday, March 30, 2010 5:39 AM

    S 1 Reply Last reply
    0
    • U User 4417354

      Hi I have DatePicker and the Maxdate is set to today: I am struggling with the MinDate. I need to set the Mindate to the 1st of 3 Months back(Keep in mind that the current month will be 3rd Month). Ex.1 For instance if we work it out as today the MinDate has to be: 01 January 2010 Ex.2 if today is the 16th of April 2010 the min date has to be: 01 Feb 2010 I hope someone can help me with this as I am really struggling with this calculation Thank you in advanced

      modified on Tuesday, March 30, 2010 5:39 AM

      S Offline
      S Offline
      Steven J Jowett
      wrote on last edited by
      #2

      I think this is what you want

      minDate = DateAdd(DateInterval.Month, -2, Today)
      minDate = DateAdd(DateInterval.Day, (Today.Day - 1) * -1, Today)

      Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.

      U 2 Replies Last reply
      0
      • S Steven J Jowett

        I think this is what you want

        minDate = DateAdd(DateInterval.Month, -2, Today)
        minDate = DateAdd(DateInterval.Day, (Today.Day - 1) * -1, Today)

        Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.

        U Offline
        U Offline
        User 4417354
        wrote on last edited by
        #3

        Thank you Steven, but if I work it from todays day it should be 01/01/2010 but the result your code gives is 3/1/2010. I do appreciate your effort in helping.I'll try to work with this code and try to change it. Thank you so much

        1 Reply Last reply
        0
        • S Steven J Jowett

          I think this is what you want

          minDate = DateAdd(DateInterval.Month, -2, Today)
          minDate = DateAdd(DateInterval.Day, (Today.Day - 1) * -1, Today)

          Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.

          U Offline
          U Offline
          User 4417354
          wrote on last edited by
          #4

          Thank you so much Steven I have changed the second line of code and replaced today with mindate and its working perfect. Im just wondering now what would happen if this month has 31 days and 3 months back has only 30.

          S 1 Reply Last reply
          0
          • U User 4417354

            Thank you so much Steven I have changed the second line of code and replaced today with mindate and its working perfect. Im just wondering now what would happen if this month has 31 days and 3 months back has only 30.

            S Offline
            S Offline
            Steven J Jowett
            wrote on last edited by
            #5

            Member 4420534 wrote:

            Im just wondering now what would happen if this month has 31 days and 3 months back has only 30

            Either reset your system clock to an appropriate date (not forgetting Feburary only has 28 days or 29 on Leap years). Define a DateTime varable and use the DateSerial function to populate it with your test date, then use the testing dateTime variable instead of the current system date, to test your code.

            Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.

            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