Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
my question is how to change date from another date.
e.g my date is '2016-05-23 10:53:07.913' and i want date 2016-05-22 10:53:07.913(one day minus)
OR If i want change value from 39;2016-05-01 to 2016-04-30(here one day minus but also change month)
in simple word i want change one date automatically from another date,
in my code only change day.if i change date on first day it change last month day..

please share..

What I have tried:

SQL
set @StartDate='2016-05-13 10:53:07.913'
       
 set @b='2016-05-23 10:53:07.913'               
 if(@StartDate<=@b)  
    begin  
    set @abc=(SELECT DATEADD(day,-1,'2016-05-23 10:53:07.913' )) 
    (SELECT DATEADD(Month,-1,'2016-05-23 10:53:07.913' ))
         
   end  
   else  
   begin   
    set @b=@b  
   end  
   
   declare @q int=( select DATEDIFF(dd,'2016-05-13 10:53:07.913','2016-05-23 10:53:07.913'))
   select @q
Posted
v2
Comments
OriginalGriff 13-May-16 3:05am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
And what you show doesn't make a whole lot of sense. What exactly are you trying to do?
Use the "Improve question" widget to edit your question and provide better information.

1 solution

Is this not want you want?

DECLARE @Date1 DATETIME = N'2016-05-23 10:53:07.913'


SELECT DATEADD(DAY, -1, @Date1)
 
Share this answer
 

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