• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 33828
  • Last Modified:

SQL DateTime Variable

Hi,

I have a DateTime variable:

DECLARE @Date datetime
SET @Date = '2007-07-20'

After I'm done with this, How can I modify the @Date variable to something like this:

DECLARE @ModifiedDate datetime
set @ModifiedDate = @Date
dateadd(hh,23,@ModifiedDate)    -- This gives me an error, Do you know how I can do this?
dateadd(mi,59,@ModifiedDate)      -- This gives me an error,
dateadd(ss,59,@ModifiedDate)      -- This gives me an error,

Thank you.
0
Endelm
Asked:
Endelm
  • 2
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
set @ModifiedDate = @Date
SET @ModifiedDate =  dateadd(hh,23,@ModifiedDate)    -- This gives me an error, Do you know how I can do this?
SET @ModifiedDate = dateadd(mi,59,@ModifiedDate)      -- This gives me an error,
SET @ModifiedDate = dateadd(ss,59,@ModifiedDate)      -- This gives me an error,
0
 
derekkrommCommented:
DECLARE @ModifiedDate datetime
set @ModifiedDate = @Date
set @ModifiedDate = dateadd(hh,23,@ModifiedDate)    
set @ModifiedDate = dateadd(mi,59,@ModifiedDate)    
set @ModifiedDate = dateadd(ss,59,@ModifiedDate)      

select @modifieddate
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
DECLARE @Date datetime
SET @Date = '2007-07-20'


DECLARE @ModifiedDate datetime
set @ModifiedDate = @Date
SET @ModifiedDate =  dateadd(hh,23,@ModifiedDate)    -- This gives me an error, Do you know how I can do this?
SELECT @ModifiedDate
SET @ModifiedDate = dateadd(mi,59,@ModifiedDate)      -- This gives me an error,
SELECT @ModifiedDate
SET @ModifiedDate = dateadd(ss,59,@ModifiedDate)      -- This gives me an error,
SELECT @ModifiedDate
0
 
EndelmAuthor Commented:
Arg! Thank you :)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now