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. Database & SysAdmin
  3. Database
  4. Verify my understanding

Verify my understanding

Scheduled Pinned Locked Moved Database
phpdatabasecomtoolsquestion
3 Posts 3 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.
  • S Offline
    S Offline
    Syed Mehroz Alam
    wrote on last edited by
    #1

    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
    end

    if len(@Day) = 1
    begin
    set @Day = '0'+@Day
    end

    set @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
    end

    if len(@Day) = 1
    begin
    set @Day = '0'+@Day
    end

    set @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

    S 1 Reply Last reply
    0
    • S Syed Mehroz Alam

      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
      end

      if len(@Day) = 1
      begin
      set @Day = '0'+@Day
      end

      set @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
      end

      if len(@Day) = 1
      begin
      set @Day = '0'+@Day
      end

      set @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

      S Offline
      S Offline
      Steve Westbrook
      wrote on last edited by
      #2

      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.

      B 1 Reply Last reply
      0
      • S Steve Westbrook

        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.

        B Offline
        B Offline
        Ben Fair
        wrote on last edited by
        #3

        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)

        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