Thread: date function

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Sweden
    Posts
    6
    Rep Power
    0

    date function


    How do I change this function so that it shows dates like this 2003-05-03 and not 2003-5-3?
    And I also want to add a parameter so that the user can choose if it should show :
    2003-03-03 or 03-03-03

    create function ShowDate(@indate datetime, @separator char(1))
    returns nchar(20)
    as
    begin
    return
    convert(nvarchar(20), datepart(yyyy, @indate))
    + @separator
    + convert(nvarchar(20), datepart(mm, @indate))
    + @separator
    + convert(nvarchar(20), datepart(dd, @indate))
    end
  2. #2
  3. Digitally Challenged
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    280
    Rep Power
    12
    this will get your date the way you want it, except it uses . instead of - as a seperator. what programming language are you using to display this data?

    select convert(varchar(20),date_field,102) as 'date' from table_name
    My brain cells are like a storm trooper's armor: useless
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Sweden
    Posts
    6
    Rep Power
    0
    I solved my problem by sitting up all night, but thanks for your input!

IMN logo majestic logo threadwatch logo seochat tools logo