Click here to Skip to main content
15,879,490 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have Crea_Date column which is a DateTime Column. I want to subtract the value in the IST column from crea_date Column and return a new column with the DateTime Value in it. My sample data is like this:

SQL
States  crea_date       IST
AB  2014-12-30 15:01:00.000 12:30:00.0000000
AK  2014-12-29 16:32:00.000 10:30:00.0000000
AZ  2014-12-18 16:07:00.000 11:30:00.0000000

Thanks in Advance
Posted
Updated 22-Jan-15 18:33pm
v2
Comments
Zoltán Zörgő 22-Jan-15 14:57pm    
Any progress?

As I know there is no other built-in method but to used DATEPART to extract hour, minute and second from the time field and use DATEDADD to substract these values from the original field value. It won't be a nice formula, but will work.
 
Share this answer
 
v2
Comments
Richard Deeming 22-Jan-15 9:43am    
Shouldn't that be "... use DATEADD to subtract ..."?
DATEDIFF is for getting the difference between two dates. :)
Zoltán Zörgő 22-Jan-15 9:55am    
Right! Thank you. Corrected.
Please check whether this works
http://stackoverflow.com/questions/13759278/how-can-i-subtract-6-hour-from-the-current-time[^]

http://stackoverflow.com/questions/3993226/c-whats-the-easiest-way-to-subtract-time[^]

Both these links recommending to use DateTime.Add(TimeSpan) method as a solution.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900