Avatar of Bob Butcher
Bob ButcherFlag for United States of America

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.
Microsoft SQL Server 2005Microsoft SQL Server 2008

Avatar of undefined
Last Comment
Bob Butcher
Avatar of vvk
vvk

since it is logically datetime value, you need to substract 2 of what? minutes, seconds, days, ticks?
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bob Butcher
Bob Butcher
Flag of United States of America image

ASKER

I need to subtract 2 from days only from that float field.
Avatar of Bob Butcher
Bob Butcher
Flag of United States of America image

ASKER

This code is exactly what I needed. Thank you.
Microsoft SQL Server 2005
Microsoft SQL Server 2005

Microsoft SQL Server 2005 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. It includes support for managing XML data and allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests.

72K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo