Verify my understanding
-
Given the T-SQL statments below, it seems that the statements do nothing other than splitting the @MinDate and @MaxDate into day, month and year and then recreating it. Before deleting this portion, can you people verify that I am not missing any perspective.
select @MinDate = min(TheDate) from tDate where TheDate > convert(datetime,'01-01-1980',105)
select @MaxDate = max(TheDate) from tDate--The following statements are not doing anything meaningful, I believe.
set @Year = datepart(yyyy,@MinDate)
set @Month = datepart(mm,@MinDate)
set @Day = datepart(d,@MinDate)if len(@Month) = 1
begin
set @Month = '0'+@Month
endif len(@Day) = 1
begin
set @Day = '0'+@Day
endset @MinDate = convert(datetime,@Day+'-'+@Month+'-'+@Year,105)
set @Year = datepart(yyyy,@MaxDate)
set @Month = datepart(mm,@MaxDate)
set @Day = datepart(d,@MaxDate)if len(@Month) = 1
begin
set @Month = '0'+@Month
endif len(@Day) = 1
begin
set @Day = '0'+@Day
endset @MaxDate = convert(datetime,@Day+'-'+@Month+'-'+@Year,105)
Regards, Syed Mehroz Alam
My Blog My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein
-
Given the T-SQL statments below, it seems that the statements do nothing other than splitting the @MinDate and @MaxDate into day, month and year and then recreating it. Before deleting this portion, can you people verify that I am not missing any perspective.
select @MinDate = min(TheDate) from tDate where TheDate > convert(datetime,'01-01-1980',105)
select @MaxDate = max(TheDate) from tDate--The following statements are not doing anything meaningful, I believe.
set @Year = datepart(yyyy,@MinDate)
set @Month = datepart(mm,@MinDate)
set @Day = datepart(d,@MinDate)if len(@Month) = 1
begin
set @Month = '0'+@Month
endif len(@Day) = 1
begin
set @Day = '0'+@Day
endset @MinDate = convert(datetime,@Day+'-'+@Month+'-'+@Year,105)
set @Year = datepart(yyyy,@MaxDate)
set @Month = datepart(mm,@MaxDate)
set @Day = datepart(d,@MaxDate)if len(@Month) = 1
begin
set @Month = '0'+@Month
endif len(@Day) = 1
begin
set @Day = '0'+@Day
endset @MaxDate = convert(datetime,@Day+'-'+@Month+'-'+@Year,105)
Regards, Syed Mehroz Alam
My Blog My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein
The original developer, may he suffer a lifetime of minor aches and pains, appears to be preparing for some kind of string-parsing which requires each portion of the date to have two characters. This would be better accomplished by ensuring the format of the incoming date; however, I would say you're more likely to cause harm by taking this out than you are by leaving it in. If, on the other hand, you want this script to be portable to a server with different internationalization settings (e.g. month/day/year), then nuke this immediately.
-
The original developer, may he suffer a lifetime of minor aches and pains, appears to be preparing for some kind of string-parsing which requires each portion of the date to have two characters. This would be better accomplished by ensuring the format of the incoming date; however, I would say you're more likely to cause harm by taking this out than you are by leaving it in. If, on the other hand, you want this script to be portable to a server with different internationalization settings (e.g. month/day/year), then nuke this immediately.
This also has the effect of stripping any time values off of the dates. They are datetime values and the time portion may not be used, but if there is a time portion it is being removed and only the date is used. If for some reason that is the goal, I think it's better done this way:
cast(convert(char(10), @datetime, 101) as datetime)
Keep It Simple Stupid! (KISS)