Set Date - @BeginDate

  • Hi,

    I have two variables declared,

    @BeginDate datetime

    @EndDate datetime

    I need to set the first variable to 01/01 of every year..ie if the current year is 2009 then @begindate should be 01/01/2009,

    if its 2010 the @BeginDate should be set to 01/01/2010. The year part should dynamically change depending on the current year.

    Please advice..

    Thanks in advance,

    Nemo-4828

  • This should work but I don't have a SQL 7 or 2000 instance to test on.

    DECLARE @BeginDate DATETIME

    DECLARE @EndDate DATETIME

    SELECT @BeginDate = DATEADD(YEAR,DATEDIFF(YEAR,0,GETDATE()),0)

    SELECT @BeginDate

  • It works....

    Thanks Matt

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply