• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

MS SQL -- GetDate(), without -, subtract 7 days ?

Below works, but updates to YYYY-MM-DD with DD of 3006 instead of taking 7 days away.

How can I change so it
 1. updates to YYYYMMDD without "-" and
 2. subtracts 7 days ?

update subscriptions
set parameters =
    substring(parameters, 1, 67)  +
    (select CONVERT(char(10), GetDate()-7,126)) + --ORIGINALLY substring(parameters, 68,8)   +
    substring(parameters, 76, 73) +
    (select CONVERT(char(10), GetDate(),126)) + --ORIGINALLY substring(parameters, 149,8)  +
    substring(parameters, 157, 999)
where subscriptionID in
  • 2
1 Solution
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
let me know if this floats your boat
SELECT CONVERT(char(8), DATEADD(D, -7, GetDate()),112) 

Open in new window

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now