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

    Join Date
    Feb 2012
    Posts
    7
    Rep Power
    0

    How to convert this date


    Hello all...first time here and i am having a bit of trouble converting a date in sql

    Currently in my column i have date format as YYYYMMDDHHMMSS

    YYYY=Year
    MM=Month
    DD=Day
    HH=Hour
    MM= Min
    SS=Sec

    i would like to convert it to CYYMMDD
    C=Century
    YY=Year
    MM=Month
    DD=Day

    Thanks
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    724
    Rep Power
    291
    Read More Here


    Code:
    declare @i datetime
    set @i = getdate()
    
    select @i,
    substring(
    	cast(datepart(yyyy,@i) as varchar(5))
    ,1,2) as [Century],
    substring(
    	cast(datepart(yyyy,@i) as varchar(5))
    ,3,2) as [Year],
    datepart(mm,@i) as [Month],
    datepart(dd,@i) as [Day]

IMN logo majestic logo threadwatch logo seochat tools logo