#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    7
    Rep Power
    0

    Date minus 1 day help please


    Hi all, i have a date in varchar format 080601(Jun 1, 2008)
    i need to minus one day from this to get 080531(May 31,2008)
    how can i do this when the format is in varchar?
    thanks
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,143
    Rep Power
    4274
    Code:
    DATEADD(D,-1,CONVERT(DATE,yourcolumn,12))
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    7
    Rep Power
    0
    Originally Posted by r937
    Code:
    DATEADD(D,-1,CONVERT(DATE,yourcolumn,12))
    thanks r937,
    now i would only like to minus one day if the date is the first of the month
    so basically if the date is 080116(jan 16 2008) i dont want it to minus 1 day for this date
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,143
    Rep Power
    4274
    Originally Posted by Biznez
    now i would only like to minus one day if the date is the first of the month
    Date minus 1 day help please

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo