Update all date columns in SQL Server -1 day
I want to update my database (SQL Server Express) all the dates for specific ids.
I am displaying the ids I want to.
SELECT TOP (1000) ID, Dates
FROM tbl_table
WHERE (id IN (29695, 29700, 29701, 29702, 29703, 29704, 29705, 29706, 29707, 29708, 29709, 29710, 29711, 29712, 29713, 29714, 29715))
AND my dates in the database are like this:
Is there any way to update all the date columns with same date - 1 day?
For example: if we have 2019-12-20
, update it to 2019-12-19
?
For example if I want to do it in PHP, I would loop through this query and fetch all all dates. After I would remove one day like this:
date('m/d/Y', strtotime($date. ' - 1 days');
And create a query to update all the columns based on id. I just want to avoid that. Is there any SQL command that do that?
Thanks
sql sql-server database date datetime
add a comment |
I want to update my database (SQL Server Express) all the dates for specific ids.
I am displaying the ids I want to.
SELECT TOP (1000) ID, Dates
FROM tbl_table
WHERE (id IN (29695, 29700, 29701, 29702, 29703, 29704, 29705, 29706, 29707, 29708, 29709, 29710, 29711, 29712, 29713, 29714, 29715))
AND my dates in the database are like this:
Is there any way to update all the date columns with same date - 1 day?
For example: if we have 2019-12-20
, update it to 2019-12-19
?
For example if I want to do it in PHP, I would loop through this query and fetch all all dates. After I would remove one day like this:
date('m/d/Y', strtotime($date. ' - 1 days');
And create a query to update all the columns based on id. I just want to avoid that. Is there any SQL command that do that?
Thanks
sql sql-server database date datetime
add a comment |
I want to update my database (SQL Server Express) all the dates for specific ids.
I am displaying the ids I want to.
SELECT TOP (1000) ID, Dates
FROM tbl_table
WHERE (id IN (29695, 29700, 29701, 29702, 29703, 29704, 29705, 29706, 29707, 29708, 29709, 29710, 29711, 29712, 29713, 29714, 29715))
AND my dates in the database are like this:
Is there any way to update all the date columns with same date - 1 day?
For example: if we have 2019-12-20
, update it to 2019-12-19
?
For example if I want to do it in PHP, I would loop through this query and fetch all all dates. After I would remove one day like this:
date('m/d/Y', strtotime($date. ' - 1 days');
And create a query to update all the columns based on id. I just want to avoid that. Is there any SQL command that do that?
Thanks
sql sql-server database date datetime
I want to update my database (SQL Server Express) all the dates for specific ids.
I am displaying the ids I want to.
SELECT TOP (1000) ID, Dates
FROM tbl_table
WHERE (id IN (29695, 29700, 29701, 29702, 29703, 29704, 29705, 29706, 29707, 29708, 29709, 29710, 29711, 29712, 29713, 29714, 29715))
AND my dates in the database are like this:
Is there any way to update all the date columns with same date - 1 day?
For example: if we have 2019-12-20
, update it to 2019-12-19
?
For example if I want to do it in PHP, I would loop through this query and fetch all all dates. After I would remove one day like this:
date('m/d/Y', strtotime($date. ' - 1 days');
And create a query to update all the columns based on id. I just want to avoid that. Is there any SQL command that do that?
Thanks
sql sql-server database date datetime
sql sql-server database date datetime
edited Mar 21 '18 at 17:51
marc_s
575k12811111258
575k12811111258
asked Mar 21 '18 at 16:16
MariaMaria
379314
379314
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
The request below will update the rows you want by adding -1 days on each date:
UPDATE tbl_table
SET dates = Dateadd(day, -1, dates)
WHERE id IN ( 29695, 29700, 29701, 29702,
29703, 29704, 29705, 29706,
29707, 29708, 29709, 29710,
29711, 29712, 29713, 29714, 29715 )
DATEADD
function takes 3 parameters:
- the
interval
( day, month, year ..) - the
increment
(the value to add or remove if negative) - an
expression
(wich is a datetime type)
See DATEADD documentation
add a comment |
To return a query with the previous day:
SELECT TOP (1000) ID, Dates, DATEADD(dd, -1, Dates) AS PreviousDay
FROM tbl_table
To update the table with the previous day:
UPDATE tbl_table
SET Dates = DATEADD(dd, -1, Dates)
FROM -- Put your conditions here
add a comment |
UPDATE tableName SET date= DATEADD(d,-1, date)
where ....
( here you put where clause for you required)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49411498%2fupdate-all-date-columns-in-sql-server-1-day%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The request below will update the rows you want by adding -1 days on each date:
UPDATE tbl_table
SET dates = Dateadd(day, -1, dates)
WHERE id IN ( 29695, 29700, 29701, 29702,
29703, 29704, 29705, 29706,
29707, 29708, 29709, 29710,
29711, 29712, 29713, 29714, 29715 )
DATEADD
function takes 3 parameters:
- the
interval
( day, month, year ..) - the
increment
(the value to add or remove if negative) - an
expression
(wich is a datetime type)
See DATEADD documentation
add a comment |
The request below will update the rows you want by adding -1 days on each date:
UPDATE tbl_table
SET dates = Dateadd(day, -1, dates)
WHERE id IN ( 29695, 29700, 29701, 29702,
29703, 29704, 29705, 29706,
29707, 29708, 29709, 29710,
29711, 29712, 29713, 29714, 29715 )
DATEADD
function takes 3 parameters:
- the
interval
( day, month, year ..) - the
increment
(the value to add or remove if negative) - an
expression
(wich is a datetime type)
See DATEADD documentation
add a comment |
The request below will update the rows you want by adding -1 days on each date:
UPDATE tbl_table
SET dates = Dateadd(day, -1, dates)
WHERE id IN ( 29695, 29700, 29701, 29702,
29703, 29704, 29705, 29706,
29707, 29708, 29709, 29710,
29711, 29712, 29713, 29714, 29715 )
DATEADD
function takes 3 parameters:
- the
interval
( day, month, year ..) - the
increment
(the value to add or remove if negative) - an
expression
(wich is a datetime type)
See DATEADD documentation
The request below will update the rows you want by adding -1 days on each date:
UPDATE tbl_table
SET dates = Dateadd(day, -1, dates)
WHERE id IN ( 29695, 29700, 29701, 29702,
29703, 29704, 29705, 29706,
29707, 29708, 29709, 29710,
29711, 29712, 29713, 29714, 29715 )
DATEADD
function takes 3 parameters:
- the
interval
( day, month, year ..) - the
increment
(the value to add or remove if negative) - an
expression
(wich is a datetime type)
See DATEADD documentation
edited Nov 13 '18 at 8:47
octano
208415
208415
answered Mar 21 '18 at 16:19
KobiKobi
2,163924
2,163924
add a comment |
add a comment |
To return a query with the previous day:
SELECT TOP (1000) ID, Dates, DATEADD(dd, -1, Dates) AS PreviousDay
FROM tbl_table
To update the table with the previous day:
UPDATE tbl_table
SET Dates = DATEADD(dd, -1, Dates)
FROM -- Put your conditions here
add a comment |
To return a query with the previous day:
SELECT TOP (1000) ID, Dates, DATEADD(dd, -1, Dates) AS PreviousDay
FROM tbl_table
To update the table with the previous day:
UPDATE tbl_table
SET Dates = DATEADD(dd, -1, Dates)
FROM -- Put your conditions here
add a comment |
To return a query with the previous day:
SELECT TOP (1000) ID, Dates, DATEADD(dd, -1, Dates) AS PreviousDay
FROM tbl_table
To update the table with the previous day:
UPDATE tbl_table
SET Dates = DATEADD(dd, -1, Dates)
FROM -- Put your conditions here
To return a query with the previous day:
SELECT TOP (1000) ID, Dates, DATEADD(dd, -1, Dates) AS PreviousDay
FROM tbl_table
To update the table with the previous day:
UPDATE tbl_table
SET Dates = DATEADD(dd, -1, Dates)
FROM -- Put your conditions here
answered Mar 21 '18 at 16:22
RyanRyan
6,31822232
6,31822232
add a comment |
add a comment |
UPDATE tableName SET date= DATEADD(d,-1, date)
where ....
( here you put where clause for you required)
add a comment |
UPDATE tableName SET date= DATEADD(d,-1, date)
where ....
( here you put where clause for you required)
add a comment |
UPDATE tableName SET date= DATEADD(d,-1, date)
where ....
( here you put where clause for you required)
UPDATE tableName SET date= DATEADD(d,-1, date)
where ....
( here you put where clause for you required)
edited Nov 13 '18 at 8:21
Vineeth Sai
2,48751323
2,48751323
answered Nov 13 '18 at 7:58
zulqarnainzulqarnain
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49411498%2fupdate-all-date-columns-in-sql-server-1-day%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown