Hi
I have below value in Database . It is DateTime field. Database is Sql. I want to add 2 weeks in Date , other values remain same.
2023-04-01 15:15:00.000
Thanks
Hi
I have below value in Database . It is DateTime field. Database is Sql. I want to add 2 weeks in Date , other values remain same.
2023-04-01 15:15:00.000
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh KumarRank #91 · 22.9K reputationPosted Mar 31, 2023, 5:40 AM EDT
Hello Ramco,
below one is correct, if you are using .AddDays() method it will not change time. it only adds days, beloow one only adds number of weeks which you have selected from dropdown
Rec.SessionDate = Convert.ToDateTime(Rec.SDate).AddDays(7*Convert.ToInt32(ddlWeeks.SelectedValue));Jignesh KumarRank #91 · 22.9K reputationPosted Mar 31, 2023, 2:08 AM EDT
Hello Ramco,
You can use DateADD() function to do this, please try below,
select DATEADD(WEEK, 2, GETDATE()) -- this will add 2 week to today's date declare @id int = 1 update tablename set yourDatefield = DATEADD(WEEK, 2, yourDatefield) where id=@id -- @id is parameterRamco RamcoRank #462 · 5.4K reputationPosted Mar 31, 2023, 2:11 AM EDT
Hi
I am trying below cide. Is it ok
Rec.SessionDate = Convert.ToDateTime(Rec.SDate).AddDays(7*Convert.ToInt32(ddlWeeks.SelectedValue));
I want to change only date. Time should remain same. With above code it is changing tome to 0.
Thanks
Rajkiran SwainRank #165 · 14.4K reputationPosted Mar 31, 2023, 2:33 AM EDT
To add 2 weeks to a date in SQL Server, you can use the DATEADD function. Here is an example query that adds 2 weeks to the date 2023-04-01 15:15:00.000: SELECT DATEADD(week, 2, '2023-04-01 15:15:00.000') This will return the date 2023-04-15 15:15:00.000. If you want to update the value in the database to reflect the new date, you can use an UPDATE statement: UPDATE MyTable SET MyDateColumn = DATEADD(week, 2, MyDateColumn) WHERE MyPrimaryKeyColumn = 123 This will add 2 weeks to the MyDateColumn value for the row with primary key 123 in MyTable.Ramco RamcoRank #462 · 5.4K reputationPosted Mar 31, 2023, 2:37 AM EDT
Hi
How to do in c#. I want chane only Date Time Values should remain same.
Thanks