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. Other Discussions
  3. The Weird and The Wonderful
  4. VB Date Nonsense

VB Date Nonsense

Scheduled Pinned Locked Moved The Weird and The Wonderful
20 Posts 16 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.
  • R Offline
    R Offline
    Rob Grainger
    wrote on last edited by
    #1

    Speaks for itself really...

    Public Function WhichYear(MyDate As Date) As Integer
    If MyDate >= CDate("01/01/2006") And MyDate <= CDate("31/12/2006") Then WhichYear = 1
    If MyDate >= CDate("01/01/2007") And MyDate <= CDate("31/12/2007") Then WhichYear = 2
    If MyDate >= CDate("01/01/2008") And MyDate <= CDate("31/12/2008") Then WhichYear = 3
    If MyDate >= CDate("01/01/2009") And MyDate <= CDate("31/12/2009") Then WhichYear = 4
    If MyDate >= CDate("01/01/2010") And MyDate <= CDate("31/12/2010") Then WhichYear = 5
    If MyDate >= CDate("01/01/2011") And MyDate <= CDate("31/12/2011") Then WhichYear = 6
    If MyDate >= CDate("01/01/2012") And MyDate <= CDate("31/12/2012") Then WhichYear = 7
    If MyDate >= CDate("01/01/2013") And MyDate <= CDate("31/12/2013") Then WhichYear = 8
    If MyDate >= CDate("01/01/2014") And MyDate <= CDate("31/12/2014") Then WhichYear = 9
    If MyDate >= CDate("01/01/2015") And MyDate <= CDate("31/12/2015") Then WhichYear = 10
    If MyDate >= CDate("01/01/2016") And MyDate <= CDate("31/12/2016") Then WhichYear = 11
    End Function

    "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

    N P J M P 9 Replies Last reply
    0
    • R Rob Grainger

      Speaks for itself really...

      Public Function WhichYear(MyDate As Date) As Integer
      If MyDate >= CDate("01/01/2006") And MyDate <= CDate("31/12/2006") Then WhichYear = 1
      If MyDate >= CDate("01/01/2007") And MyDate <= CDate("31/12/2007") Then WhichYear = 2
      If MyDate >= CDate("01/01/2008") And MyDate <= CDate("31/12/2008") Then WhichYear = 3
      If MyDate >= CDate("01/01/2009") And MyDate <= CDate("31/12/2009") Then WhichYear = 4
      If MyDate >= CDate("01/01/2010") And MyDate <= CDate("31/12/2010") Then WhichYear = 5
      If MyDate >= CDate("01/01/2011") And MyDate <= CDate("31/12/2011") Then WhichYear = 6
      If MyDate >= CDate("01/01/2012") And MyDate <= CDate("31/12/2012") Then WhichYear = 7
      If MyDate >= CDate("01/01/2013") And MyDate <= CDate("31/12/2013") Then WhichYear = 8
      If MyDate >= CDate("01/01/2014") And MyDate <= CDate("31/12/2014") Then WhichYear = 9
      If MyDate >= CDate("01/01/2015") And MyDate <= CDate("31/12/2015") Then WhichYear = 10
      If MyDate >= CDate("01/01/2016") And MyDate <= CDate("31/12/2016") Then WhichYear = 11
      End Function

      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      Perfectly sensible code, if you're 3 years old. And dead.

      R 1 Reply Last reply
      0
      • R Rob Grainger

        Speaks for itself really...

        Public Function WhichYear(MyDate As Date) As Integer
        If MyDate >= CDate("01/01/2006") And MyDate <= CDate("31/12/2006") Then WhichYear = 1
        If MyDate >= CDate("01/01/2007") And MyDate <= CDate("31/12/2007") Then WhichYear = 2
        If MyDate >= CDate("01/01/2008") And MyDate <= CDate("31/12/2008") Then WhichYear = 3
        If MyDate >= CDate("01/01/2009") And MyDate <= CDate("31/12/2009") Then WhichYear = 4
        If MyDate >= CDate("01/01/2010") And MyDate <= CDate("31/12/2010") Then WhichYear = 5
        If MyDate >= CDate("01/01/2011") And MyDate <= CDate("31/12/2011") Then WhichYear = 6
        If MyDate >= CDate("01/01/2012") And MyDate <= CDate("31/12/2012") Then WhichYear = 7
        If MyDate >= CDate("01/01/2013") And MyDate <= CDate("31/12/2013") Then WhichYear = 8
        If MyDate >= CDate("01/01/2014") And MyDate <= CDate("31/12/2014") Then WhichYear = 9
        If MyDate >= CDate("01/01/2015") And MyDate <= CDate("31/12/2015") Then WhichYear = 10
        If MyDate >= CDate("01/01/2016") And MyDate <= CDate("31/12/2016") Then WhichYear = 11
        End Function

        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Oh my.

        This space intentionally left blank.

        1 Reply Last reply
        0
        • R Rob Grainger

          Speaks for itself really...

          Public Function WhichYear(MyDate As Date) As Integer
          If MyDate >= CDate("01/01/2006") And MyDate <= CDate("31/12/2006") Then WhichYear = 1
          If MyDate >= CDate("01/01/2007") And MyDate <= CDate("31/12/2007") Then WhichYear = 2
          If MyDate >= CDate("01/01/2008") And MyDate <= CDate("31/12/2008") Then WhichYear = 3
          If MyDate >= CDate("01/01/2009") And MyDate <= CDate("31/12/2009") Then WhichYear = 4
          If MyDate >= CDate("01/01/2010") And MyDate <= CDate("31/12/2010") Then WhichYear = 5
          If MyDate >= CDate("01/01/2011") And MyDate <= CDate("31/12/2011") Then WhichYear = 6
          If MyDate >= CDate("01/01/2012") And MyDate <= CDate("31/12/2012") Then WhichYear = 7
          If MyDate >= CDate("01/01/2013") And MyDate <= CDate("31/12/2013") Then WhichYear = 8
          If MyDate >= CDate("01/01/2014") And MyDate <= CDate("31/12/2014") Then WhichYear = 9
          If MyDate >= CDate("01/01/2015") And MyDate <= CDate("31/12/2015") Then WhichYear = 10
          If MyDate >= CDate("01/01/2016") And MyDate <= CDate("31/12/2016") Then WhichYear = 11
          End Function

          "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

          M Offline
          M Offline
          MarqW
          wrote on last edited by
          #4

          I would argue that it's not nonsense - you can tell by looking at it exactly what it does - it's just not the best way of doing it :)

          Z 1 Reply Last reply
          0
          • R Rob Grainger

            Speaks for itself really...

            Public Function WhichYear(MyDate As Date) As Integer
            If MyDate >= CDate("01/01/2006") And MyDate <= CDate("31/12/2006") Then WhichYear = 1
            If MyDate >= CDate("01/01/2007") And MyDate <= CDate("31/12/2007") Then WhichYear = 2
            If MyDate >= CDate("01/01/2008") And MyDate <= CDate("31/12/2008") Then WhichYear = 3
            If MyDate >= CDate("01/01/2009") And MyDate <= CDate("31/12/2009") Then WhichYear = 4
            If MyDate >= CDate("01/01/2010") And MyDate <= CDate("31/12/2010") Then WhichYear = 5
            If MyDate >= CDate("01/01/2011") And MyDate <= CDate("31/12/2011") Then WhichYear = 6
            If MyDate >= CDate("01/01/2012") And MyDate <= CDate("31/12/2012") Then WhichYear = 7
            If MyDate >= CDate("01/01/2013") And MyDate <= CDate("31/12/2013") Then WhichYear = 8
            If MyDate >= CDate("01/01/2014") And MyDate <= CDate("31/12/2014") Then WhichYear = 9
            If MyDate >= CDate("01/01/2015") And MyDate <= CDate("31/12/2015") Then WhichYear = 10
            If MyDate >= CDate("01/01/2016") And MyDate <= CDate("31/12/2016") Then WhichYear = 11
            End Function

            "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

            J Offline
            J Offline
            Jorgen Andersson
            wrote on last edited by
            #5

            My god, they should have used an enum.

            Wrong is evil and must be defeated. - Jeff Ello[^]

            R 1 Reply Last reply
            0
            • R Rob Grainger

              Speaks for itself really...

              Public Function WhichYear(MyDate As Date) As Integer
              If MyDate >= CDate("01/01/2006") And MyDate <= CDate("31/12/2006") Then WhichYear = 1
              If MyDate >= CDate("01/01/2007") And MyDate <= CDate("31/12/2007") Then WhichYear = 2
              If MyDate >= CDate("01/01/2008") And MyDate <= CDate("31/12/2008") Then WhichYear = 3
              If MyDate >= CDate("01/01/2009") And MyDate <= CDate("31/12/2009") Then WhichYear = 4
              If MyDate >= CDate("01/01/2010") And MyDate <= CDate("31/12/2010") Then WhichYear = 5
              If MyDate >= CDate("01/01/2011") And MyDate <= CDate("31/12/2011") Then WhichYear = 6
              If MyDate >= CDate("01/01/2012") And MyDate <= CDate("31/12/2012") Then WhichYear = 7
              If MyDate >= CDate("01/01/2013") And MyDate <= CDate("31/12/2013") Then WhichYear = 8
              If MyDate >= CDate("01/01/2014") And MyDate <= CDate("31/12/2014") Then WhichYear = 9
              If MyDate >= CDate("01/01/2015") And MyDate <= CDate("31/12/2015") Then WhichYear = 10
              If MyDate >= CDate("01/01/2016") And MyDate <= CDate("31/12/2016") Then WhichYear = 11
              End Function

              "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

              P Offline
              P Offline
              phil o
              wrote on last edited by
              #6

              Which year?

              while (!working) {
              Reboot();
              }

              1 Reply Last reply
              0
              • N Nagy Vilmos

                Perfectly sensible code, if you're 3 years old. And dead.

                R Offline
                R Offline
                Rob Grainger
                wrote on last edited by
                #7

                The nice thing is that it the only limit to dates was how many the developer had been bothered to type. It triggered a bug as we frequently deal with dates in the future...

                "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                J S 2 Replies Last reply
                0
                • R Rob Grainger

                  The nice thing is that it the only limit to dates was how many the developer had been bothered to type. It triggered a bug as we frequently deal with dates in the future...

                  "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                  J Offline
                  J Offline
                  Jorgen Andersson
                  wrote on last edited by
                  #8

                  Do you use it often on midday 31st of December?

                  Wrong is evil and must be defeated. - Jeff Ello[^]

                  N B 2 Replies Last reply
                  0
                  • R Rob Grainger

                    Speaks for itself really...

                    Public Function WhichYear(MyDate As Date) As Integer
                    If MyDate >= CDate("01/01/2006") And MyDate <= CDate("31/12/2006") Then WhichYear = 1
                    If MyDate >= CDate("01/01/2007") And MyDate <= CDate("31/12/2007") Then WhichYear = 2
                    If MyDate >= CDate("01/01/2008") And MyDate <= CDate("31/12/2008") Then WhichYear = 3
                    If MyDate >= CDate("01/01/2009") And MyDate <= CDate("31/12/2009") Then WhichYear = 4
                    If MyDate >= CDate("01/01/2010") And MyDate <= CDate("31/12/2010") Then WhichYear = 5
                    If MyDate >= CDate("01/01/2011") And MyDate <= CDate("31/12/2011") Then WhichYear = 6
                    If MyDate >= CDate("01/01/2012") And MyDate <= CDate("31/12/2012") Then WhichYear = 7
                    If MyDate >= CDate("01/01/2013") And MyDate <= CDate("31/12/2013") Then WhichYear = 8
                    If MyDate >= CDate("01/01/2014") And MyDate <= CDate("31/12/2014") Then WhichYear = 9
                    If MyDate >= CDate("01/01/2015") And MyDate <= CDate("31/12/2015") Then WhichYear = 10
                    If MyDate >= CDate("01/01/2016") And MyDate <= CDate("31/12/2016") Then WhichYear = 11
                    End Function

                    "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #9

                    Well...it's readable. More's the pity.

                    Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    1 Reply Last reply
                    0
                    • R Rob Grainger

                      Speaks for itself really...

                      Public Function WhichYear(MyDate As Date) As Integer
                      If MyDate >= CDate("01/01/2006") And MyDate <= CDate("31/12/2006") Then WhichYear = 1
                      If MyDate >= CDate("01/01/2007") And MyDate <= CDate("31/12/2007") Then WhichYear = 2
                      If MyDate >= CDate("01/01/2008") And MyDate <= CDate("31/12/2008") Then WhichYear = 3
                      If MyDate >= CDate("01/01/2009") And MyDate <= CDate("31/12/2009") Then WhichYear = 4
                      If MyDate >= CDate("01/01/2010") And MyDate <= CDate("31/12/2010") Then WhichYear = 5
                      If MyDate >= CDate("01/01/2011") And MyDate <= CDate("31/12/2011") Then WhichYear = 6
                      If MyDate >= CDate("01/01/2012") And MyDate <= CDate("31/12/2012") Then WhichYear = 7
                      If MyDate >= CDate("01/01/2013") And MyDate <= CDate("31/12/2013") Then WhichYear = 8
                      If MyDate >= CDate("01/01/2014") And MyDate <= CDate("31/12/2014") Then WhichYear = 9
                      If MyDate >= CDate("01/01/2015") And MyDate <= CDate("31/12/2015") Then WhichYear = 10
                      If MyDate >= CDate("01/01/2016") And MyDate <= CDate("31/12/2016") Then WhichYear = 11
                      End Function

                      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                      Kornfeld Eliyahu PeterK Offline
                      Kornfeld Eliyahu PeterK Offline
                      Kornfeld Eliyahu Peter
                      wrote on last edited by
                      #10

                      I read it ten times, and asked myself - there is a better way?! :laugh:

                      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

                      1 Reply Last reply
                      0
                      • J Jorgen Andersson

                        Do you use it often on midday 31st of December?

                        Wrong is evil and must be defeated. - Jeff Ello[^]

                        N Offline
                        N Offline
                        Nicholas Marty
                        wrote on last edited by
                        #11

                        I was wondering about that one too :D

                        1 Reply Last reply
                        0
                        • M MarqW

                          I would argue that it's not nonsense - you can tell by looking at it exactly what it does - it's just not the best way of doing it :)

                          Z Offline
                          Z Offline
                          ZurdoDev
                          wrote on last edited by
                          #12

                          Legible and nonsense are not mutually exclusive. :)

                          There are only 10 types of people in the world, those who understand binary and those who don't.

                          R 1 Reply Last reply
                          0
                          • Z ZurdoDev

                            Legible and nonsense are not mutually exclusive. :)

                            There are only 10 types of people in the world, those who understand binary and those who don't.

                            R Offline
                            R Offline
                            Rob Grainger
                            wrote on last edited by
                            #13

                            brillig

                            "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                            Richard DeemingR 1 Reply Last reply
                            0
                            • R Rob Grainger

                              brillig

                              "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                              Richard DeemingR Offline
                              Richard DeemingR Offline
                              Richard Deeming
                              wrote on last edited by
                              #14

                              Slithy tove! ;P


                              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                              1 Reply Last reply
                              0
                              • R Rob Grainger

                                Speaks for itself really...

                                Public Function WhichYear(MyDate As Date) As Integer
                                If MyDate >= CDate("01/01/2006") And MyDate <= CDate("31/12/2006") Then WhichYear = 1
                                If MyDate >= CDate("01/01/2007") And MyDate <= CDate("31/12/2007") Then WhichYear = 2
                                If MyDate >= CDate("01/01/2008") And MyDate <= CDate("31/12/2008") Then WhichYear = 3
                                If MyDate >= CDate("01/01/2009") And MyDate <= CDate("31/12/2009") Then WhichYear = 4
                                If MyDate >= CDate("01/01/2010") And MyDate <= CDate("31/12/2010") Then WhichYear = 5
                                If MyDate >= CDate("01/01/2011") And MyDate <= CDate("31/12/2011") Then WhichYear = 6
                                If MyDate >= CDate("01/01/2012") And MyDate <= CDate("31/12/2012") Then WhichYear = 7
                                If MyDate >= CDate("01/01/2013") And MyDate <= CDate("31/12/2013") Then WhichYear = 8
                                If MyDate >= CDate("01/01/2014") And MyDate <= CDate("31/12/2014") Then WhichYear = 9
                                If MyDate >= CDate("01/01/2015") And MyDate <= CDate("31/12/2015") Then WhichYear = 10
                                If MyDate >= CDate("01/01/2016") And MyDate <= CDate("31/12/2016") Then WhichYear = 11
                                End Function

                                "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                                A Offline
                                A Offline
                                Andre Kraak
                                wrote on last edited by
                                #15

                                Always nice to know in advance when you are going to stop supporting your code.

                                1 Reply Last reply
                                0
                                • R Rob Grainger

                                  Speaks for itself really...

                                  Public Function WhichYear(MyDate As Date) As Integer
                                  If MyDate >= CDate("01/01/2006") And MyDate <= CDate("31/12/2006") Then WhichYear = 1
                                  If MyDate >= CDate("01/01/2007") And MyDate <= CDate("31/12/2007") Then WhichYear = 2
                                  If MyDate >= CDate("01/01/2008") And MyDate <= CDate("31/12/2008") Then WhichYear = 3
                                  If MyDate >= CDate("01/01/2009") And MyDate <= CDate("31/12/2009") Then WhichYear = 4
                                  If MyDate >= CDate("01/01/2010") And MyDate <= CDate("31/12/2010") Then WhichYear = 5
                                  If MyDate >= CDate("01/01/2011") And MyDate <= CDate("31/12/2011") Then WhichYear = 6
                                  If MyDate >= CDate("01/01/2012") And MyDate <= CDate("31/12/2012") Then WhichYear = 7
                                  If MyDate >= CDate("01/01/2013") And MyDate <= CDate("31/12/2013") Then WhichYear = 8
                                  If MyDate >= CDate("01/01/2014") And MyDate <= CDate("31/12/2014") Then WhichYear = 9
                                  If MyDate >= CDate("01/01/2015") And MyDate <= CDate("31/12/2015") Then WhichYear = 10
                                  If MyDate >= CDate("01/01/2016") And MyDate <= CDate("31/12/2016") Then WhichYear = 11
                                  End Function

                                  "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                                  B Offline
                                  B Offline
                                  Bernhard Hiller
                                  wrote on last edited by
                                  #16

                                  That is a future proof solution. I mean: you already know now that you will be called to apply a bug fix to it soon and can charge for your professional services.

                                  J 1 Reply Last reply
                                  0
                                  • B Bernhard Hiller

                                    That is a future proof solution. I mean: you already know now that you will be called to apply a bug fix to it soon and can charge for your professional services.

                                    J Offline
                                    J Offline
                                    Jorgen Andersson
                                    wrote on last edited by
                                    #17

                                    For a certain value of professional.

                                    Wrong is evil and must be defeated. - Jeff Ello[^]

                                    1 Reply Last reply
                                    0
                                    • J Jorgen Andersson

                                      My god, they should have used an enum.

                                      Wrong is evil and must be defeated. - Jeff Ello[^]

                                      R Offline
                                      R Offline
                                      Rage
                                      wrote on last edited by
                                      #18

                                      Now that's brilliant.5.

                                      ~RaGE();

                                      I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus Do not feed the troll ! - Common proverb

                                      1 Reply Last reply
                                      0
                                      • J Jorgen Andersson

                                        Do you use it often on midday 31st of December?

                                        Wrong is evil and must be defeated. - Jeff Ello[^]

                                        B Offline
                                        B Offline
                                        BobJanova
                                        wrote on last edited by
                                        #19

                                        Year end bugs are especially brilliant because they guarantee that someone will have to be pulled out of bed (usually, as midnight rolls over) on a holiday when they really don't want to think about work, because some critical system crashed on either 31/12 (as in this case) or 1/1.

                                        1 Reply Last reply
                                        0
                                        • R Rob Grainger

                                          The nice thing is that it the only limit to dates was how many the developer had been bothered to type. It triggered a bug as we frequently deal with dates in the future...

                                          "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                                          S Offline
                                          S Offline
                                          Sergey Alexandrovich Kryukov
                                          wrote on last edited by
                                          #20

                                          Problem 2017 :-)

                                          —SA

                                          Sergey A Kryukov

                                          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