VB Date Nonsense
-
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.
-
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.
Perfectly sensible code, if you're 3 years old. And dead.
-
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.
Oh my.
This space intentionally left blank.
-
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.
-
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.
My god, they should have used an enum.
Wrong is evil and must be defeated. - Jeff Ello[^]
-
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.
-
Perfectly sensible code, if you're 3 years old. And dead.
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.
-
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.
Do you use it often on midday 31st of December?
Wrong is evil and must be defeated. - Jeff Ello[^]
-
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.
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 – ∞)
-
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.
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)
-
Do you use it often on midday 31st of December?
Wrong is evil and must be defeated. - Jeff Ello[^]
I was wondering about that one too :D
-
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 :)
-
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.
brillig
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
brillig
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
Slithy tove! ;P
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
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.
Always nice to know in advance when you are going to stop supporting your code.
-
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.
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.
-
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.
For a certain value of professional.
Wrong is evil and must be defeated. - Jeff Ello[^]
-
My god, they should have used an enum.
Wrong is evil and must be defeated. - Jeff Ello[^]
-
Do you use it often on midday 31st of December?
Wrong is evil and must be defeated. - Jeff Ello[^]
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.
-
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.
Problem 2017 :-)
—SA
Sergey A Kryukov