Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

How does DateSerial function convert INVALID dates into a VALID dates?

Aug 14 2012 12:00AM by Madhivanan   

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

Tags: 


Madhivanan
3 · 39% · 12430
9
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

2  Comments  

  • Negative values work just fine, too. If you want a date 60 months before another date that you already have broken out into parts, then DateSerial(@Year, @Month - 60, @Day) will work well. You'll need to check if this is the functionality you want, though, since a combination such as (2012, 3 - 61, 31) obviously can't return 2012-02-31 which is invalid.

    commented on Aug 14 2012 1:36PM
    ErikEckhardt
    65 · 3% · 887
  • Thanks ErikEckhardt, negavie numbers will just work fine and will give you past dates

    commented on Aug 16 2012 12:30AM
    Madhivanan
    3 · 39% · 12430

Your Comment


Sign Up or Login to post a comment.

"How does DateSerial function convert INVALID dates into a VALID dates?" rated 5 out of 5 by 9 readers
How does DateSerial function convert INVALID dates into a VALID dates? , 5.0 out of 5 based on 9 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]