Bob Butcher
asked on
how to subtract 2 from from my datetime value in t-sql
I have a field in my table called capturedate which stores a float value which looks like something like this - 40821.28441
my t-sql code is like this:
declare @mypunchdate datetime;
set @mypunchdate = cast(capturedate as datetime);
this code converts the value to a datetime value fine - now what I need to do is before I pass @mypunchdate to my stored procedure I need to subtract 2 from it - so I need to add more code above so it takes that capturedate subtracts 2 and then I put it in my @mypunchdate variable.
What would the code look like to do this above?
Thanks so much in advance. I am lost when it comes to t-sql.
my t-sql code is like this:
declare @mypunchdate datetime;
set @mypunchdate = cast(capturedate as datetime);
this code converts the value to a datetime value fine - now what I need to do is before I pass @mypunchdate to my stored procedure I need to subtract 2 from it - so I need to add more code above so it takes that capturedate subtracts 2 and then I put it in my @mypunchdate variable.
What would the code look like to do this above?
Thanks so much in advance. I am lost when it comes to t-sql.
since it is logically datetime value, you need to substract 2 of what? minutes, seconds, days, ticks?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I need to subtract 2 from days only from that float field.
ASKER
This code is exactly what I needed. Thank you.