Results 1 to 4 of 4

Thread: Date Comparison

  1. #1
    Join Date
    Apr 2005
    Posts
    4

    Unanswered: Date Comparison

    I have two tables that I am needing to link by the tables date field. In one table the date field is defined as varchar(23). The time for this field is always zeros.
    Example: '2005-12-27 00:00:00.000'

    The other table is defined as datetime, and it does have the date and time in this field.
    Example: 2005-12-27 08:00:35.000

    The problem i am having is
    2005-12-27 00:00:00.000 does not = 2005-12-27 08:00:35.000.

    Because I will never have more than one record on the same date I would like to be able to only compare the date. Example 2005-12-27 = 2005-12-27

    Since the fields are 2 different field types, this is giving me a problem. Could someone please help. I have tried everything I know to do.

    What I really need is the a way to format the datetime fields date into a string such as '2005-12-27'.

    Hopefully what i have written makes sense.

    Thanks

  2. #2
    Join Date
    Jan 2005
    Location
    Green Bay
    Posts
    201
    select cast(convert(varchar(11),getdate()) as Datetime)

    this eliminates the time stamp and sets it to 2006-05-27 00:00:00.000

    This will allow you to join

    Suggestion make your varchar field a date field.

  3. #3
    Join Date
    Jun 2003
    Posts
    269

    Thumbs up

    Or,Use the below code to convert date to varchar and compare with ur varchar field
    Code:
    select convert(varchar,DATEADD(dd, DATEDIFF(dd,0,getdate()), 0),121)
    I love cursor,though I never use it.Cos' I dont want to misuse it.
    ----------------------------------------------

    ----cheers
    ----http://mallier.blogspot.com

  4. #4
    Join Date
    Apr 2005
    Posts
    4
    That worked perfect! Thanks!

Posting Permissions

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