Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Location
    NJ USA
    Posts
    19

    Unanswered: Convert Datetime.

    Hello All,

    In following statement in SQL, I'm first converting 'IssueDate' with style 101 into 'nvarchar' then converting to Datatime.

    convert(datetime,convert (nvarchar,Cert_WarehouseDetails.IssuedDateX,101)) <= '3/29/2004')


    Which is right in below one.

    1. Do I need to first convert into nvarchar then datetime.
    e.g. convert(datetime,convert (nvarchar,Cert_WarehouseDetails.IssuedDateX,101)) <= '3/29/2004')


    2. Otherwise can I directly convert into datetime.

    convert(datetime,Cert_WarehouseDetails.IssuedDateX ,101) <= '3/29/2004')


    Please reply to me asap.


    Regards,
    M. G.
    M. Jain

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Do this

    WHERE DATEDIFF(d,'3/29/2004',IssuedDateX) < 0
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I would use:
    PHP Code:
    Convert(CHAR(10), Cert_WarehouseDetails.IssuedDateX121
    if you intend to convert it back to a datetime (to strip off the time).

    -PatP

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Doooh...

    Either way it's a scan...

    Code:
    USE Northwind
    GO
    
    --Type [CTRL]+K
    
    --Index Scan
    
    SELECT OrderDate FROM Orders
    WHERE DATEDIFF(d,'7/11/1996',OrderDate) < 0
    
    --Index Seek
    
    SELECT OrderDate FROM Orders
    WHERE OrderDate <= '7/11/1996'
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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