comparing dates with different formats

  • Hi,

    I have a date column,Date_A, from table_A in this format 2004-03-12 02:31:03.000

    and another from table_B,Date_B, in this format 04/01/2006

    I wish to joing the two table using the dates but want to disregard the seconds on Date_A.

    select *

    from

    Table_A join Table_B on Date_A = Date_B

    do I need to do a convert on the date with the seconds??

    Any help welcome

    Thanks in advance,

    Eamon

  • Maybe what datatype is Date_A and what type is Date_B. If they are not the same type I suggest doing a cast. I would suggest doing like so personally

     

    select *

    from

    Table_A join Table_B on

    cast(Date_A as datetime) = cast(Date_B as datetime)

  • Yes, convert the date to the format you want - look on BOL for teh various formats. You may have to use the LEFT function as well to trim the seconds from the date.

    Tryst

  • I suggest you cast only one of them, the one with the extended time information. You don't have to care about the format, since internally there's no difference in the storage.


    _/_/_/ paramind _/_/_/

  • Guys,

    I casted just one of then just to give me dd/mm/yyyy

    I used convert and style 103.

    Thanks,

    Eamon

  • HI,

    USE THIS QUERY,,

    select *

    from

    Table_A join Table_B on convert(datetime,convert(varchar(10),Date_A,121)) = Date_B

     

    REGARDS

    AMIT

     

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply