how to subtract date from a number?

Hi,

This is what I would like to do,

Col A is a date in the following format (2005/03/08)  and I would like to subtract this date by the number that's Col B. Then I would like the result to be in a date fromat like Col A. All the columns are varchar.

         Col A - Col B =  Col C
2005/03/08 - 4      =  2005/03/04

TIA,
Frank
fcobuzziAsked:
Who is Participating?
 
rafranciscoCommented:
UPDATE YourTable
SET ColC = CONVERT(VARCHAR(10), DATEADD(DD, -CAST(ColB AS INT), CAST(ColA AS DATETIME), 111)
0
 
rafranciscoCommented:
UPDATE YourTable
SET ColC = DATEADD(DD, -CAST(ColB AS INT), CAST(ColA AS DATETIME))
0
 
fcobuzziAuthor Commented:
 
 
That worked great but the date formats are different. My original column has the following format "2005/03/08" and the script that you gave has the following format "Mar  1 2005 12:00AM". I would like to format to be either "Mar  1,2005" or "2005/03/08".  What has to be changed in the script to change the date format?
0
 
fcobuzziAuthor Commented:
Thanks again.
Frank
0
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.

All Courses

From novice to tech pro — start learning today.