Results 1 to 9 of 9

Thread: Converting Date

  1. #1
    Join Date
    Oct 2006
    Posts
    7

    Post Unanswered: Converting Date

    I am unable to convert following date format in seconds (ss). Plz provide me query for the same.

    Date Available :


    2007-03-27 09:55:00.000

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    select convert(datetime, '2007-03-27 09:55:00.000')

    ??

  3. #3
    Join Date
    Nov 2002
    Posts
    272
    Quote Originally Posted by jezemine
    select convert(datetime, '2007-03-27 09:55:00.000')
    Yes, and the seconds are extracted by:
    select datepart(ss, convert(datetime, '2007-03-27 09:55:00.000'))

  4. #4
    Join Date
    Feb 2003
    Location
    India
    Posts
    216
    even the convet part of
    Code:
    select datepart(ss, convert(datetime, '2007-03-27 09:55:00.000'))
    can be avoided and used as

    select datepart(ss,'2007-03-27 09:55:00.000')

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    but select datepart(ss,'2007-03-27 09:55:00.000') yields 0

    i think perhaps milind wanted the answer to be 3383974800, which is that datetime converted in seconds in SQL Server

    note that in unix timestamp format, the value would be 1175003700
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Nov 2002
    Posts
    272
    Perhaps, yes. Then the query he asked would be:

    SELECT 3383974800

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    no, not really, because you don't get that answer without doing a conversion

    for example, what is the answer for '2006-09-09 09:37'?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    Join Date
    Nov 2002
    Posts
    272
    '2006-09-09 09:37' is not one of the available dates listed in the OP.

    Seriously, I think we need Milind to clarify what s/he wants.

  9. #9
    Join Date
    Feb 2003
    Location
    India
    Posts
    216
    Quote Originally Posted by ivon
    '2006-09-09 09:37' is not one of the available dates listed in the OP.
    good one

Posting Permissions

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