Results 1 to 5 of 5

Thread: date format

  1. #1
    Join Date
    Dec 2003
    Location
    Denmark
    Posts
    3

    date format

    Hi all

    i have a query like this

    SELECT i.id, i.startdate, i.duration, i.id_location
    FROM instance i, location l
    WHERE #course_id# = l.id_course
    AND i.id_location = l.id

    i get the i.startdate which is a date in a timestampformat.

    how do you format it?

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    If it is SQL Server, you can use CONVERT function with STYLE parameter to format date.

    CONVERT(varchar(30),startdate,101)

    For Oracle you have to use TO_CHAR function with format parameter

    TO_CHAR(startdate,'MMD:YYYY')

  3. #3
    Join Date
    Dec 2003
    Location
    Denmark
    Posts
    3
    Thx for the reply skhanal

    It is SQL Server

    but it says i have wrong syntax near convert....

    Is it because i run version 4.0.15

  4. #4
    Join Date
    Dec 2003
    Location
    Denmark
    Posts
    3
    i use it like this

    SELECT i.id, CONVERT(varchar30),startdate,101)
    , i.duration, i.id_location
    FROM instance i, location l
    WHERE #course_id# = l.id_course
    AND i.id_location = l.id

    is that correct?

  5. #5
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    SELECT i.id, CONVERT(varchar(30),i.startdate,101)
    , i.duration, i.id_location
    FROM instance i, location l
    WHERE #course_id# = l.id_course
    AND i.id_location = l.id


    You can try other format styles too besides 101. See books online for other options.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •