Click here to Skip to main content
15,922,419 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my project I have a start date ('regdt'-column name) in a table and number of days in a variable namely 'v_days_eligible'. Now, I want to arrive at expiry date by adding 'regdt+v_days_eligible' and update in the column 'expiry_dt' of the same table.

For current date I used the following code:

string updateSql1 = "UPDATE txfile SET expiry_dt='" + DateTime.Now.AddDays(Convert.ToInt32(v_days_eligible)).ToString("dd/MM/yyyy") + "',payment_recvd_dt=Convert(varchar(10),getdate(),105), pay_status= 'Y' " + "WHERE mem_id= " + v_mem_id + "";

How to do using the column name 'regdt'.

Can any one help me out?
Posted

1 solution

Hi,

Use DATEADD function

SQL
SELECT DATEADD(day,v_days_eligible,regdt) AS ExpiryDate
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 3-Apr-13 1:26am    
err: invalid column name 'regdt'
vijay__p 3-Apr-13 1:37am    
You have written that you have column regdt in table, if it is there then error should not be there.
try with bwlow query

string updateSql1 = "UPDATE txfile SET expiry_dt=DATEADD(day,"+v_days_eligible+",regdt),payment_recvd_dt=Convert(varchar(10),getdate(),105), pay_status= 'Y' " + "WHERE mem_id= " + v_mem_id + "";

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