I saw this question
"Date d = new SimpleDateFormat("MM/dd/yyyy").parse("22/44/2008") will return Nov 13, 2009 as the date! Really? 22 is what month?"
The code is written in Java and the user is surprised to see the result and wonders if 22 is a month.
Well. The above function is DateSerial in Java. You need to aware that a DATESERIAL function will happily accept any value as parameters and create a date which is past or future based on values. Let us take the following example
DateSerial(2012,01,32) will return Feb 01, 2012 because day part 32 will be considered as 32nd day from Jan 2012.
Similarly
DateSerial(2012,07,88) will return Sep 26, 2012 because day part 88 will be considered as 88th day from Jul 2012.
Here are the examples in T-SQL
declare @year int, @month int, @day int
select @year=2012,@month=1,@day=32
select dateadd(day,@day-1,dateadd(month,@month-1,dateadd(year,@year-1900,0))) as date
select @year=2012,@month=7,@day=88
select dateadd(day,@day-1,dateadd(month,@month-1,dateadd(year,@year-1900,0))) as date
The results are
date
-----------------------
2012-02-01 00:00:00.000
date
-----------------------
2012-09-26 00:00:00.000
Similarly see what happens when month is 22, day is 44 and year is 2008
declare @year int, @month int, @day int
select @year=2008,@month=22,@day=44
select dateadd(day,@day-1,dateadd(month,@month-1,dateadd(year,@year-1900,0))) as date
The result is
date
-----------------------
2009-11-13 00:00:00.000
So you need to aware how dateserial function converts parameter values into future dates based on the values. You may be interested to read these posts too
http://beyondrelational.com/modules/2/blogs/70/posts/15788/10-ways-to-simulate-dateserial-function.aspx http://beyondrelational.com/modules/2/blogs/70/posts/15818/10-ways-to-simulate-dateserial-function-faster-methods.aspx