date column behaving strangely

  • hi,

    i have a column that's treating dates in an odd way.

    select filldate, datediff(dd, filldate, getdate()) as Diff

    from j2551963

    group by filldate

    having datediff(dd, filldate, getdate()) < 13

    order by filldate

    filldateDiff

    03/01/201312

    03/02/201311

    03/03/201310

    03/04/20139

    03/05/20138

    03/06/20137

    03/07/20136

    03/08/20135

    select filldate, count(*) as Records

    from j2551963

    where filldate like '03/%'

    group by filldate

    order by filldate

    filldateRecords

    03/01/20132728

    03/02/20131228

    03/03/2013908

    03/04/20132525

    03/05/20132497

    03/06/20132153

    03/07/20132086

    03/08/20131726

    select convert(varchar, filldate, 101)as FillDate, count(*) as Records

    from j2551963

    group by filldate

    having datediff(dd, convert(varchar, filldate, 101), getdate()) < 13

    order by filldate

    FillDateRecords

    03/01/20132728

    03/02/20131228

    03/03/2013908

    03/04/20132525

    03/05/20132497

    03/06/20132153

    03/07/20132086

    03/08/20131726

    here is column information:

    id_FieldField_vartypeField_VarsizeSourceName

    FillDatenvarchar 64 FillDate

    data was imported from excel files. i guess my question is: how come just a few columns are recognized by the datediff without a convert statement? is it an excel issue, or an import issue? i know that's a bit open ended without posting more information, but i'm curious if there's an answer before getting deeper into it.

    thanks

  • I can't figure out what your problem is here.

  • Seems to me that the only real issue here is that you have a varchar(64) column that should be a datetime column.

    As you said yourself, there is not much information here to go on. Perhaps if you post some details we can help.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • heh. no. i had a monumental brainfart.

    i was looking at the 'diff' column like it was a count, not like it was showing the difference between the two dates.

    sorry about that, and thanks for looking. as soon as this three week old lets me get some sleep, i'll have better questions.

Viewing 4 posts - 1 through 3 (of 3 total)

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