Results 1 to 7 of 7
  1. #1
    3 Star Lounger Omega3's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles, California, USA
    Posts
    343
    Thanks
    2
    Thanked 1 Time in 1 Post

    Date Timestamp Sort Problem (Excel 2003)

    I have a query that sorts data by date. The date field is data type
    You know it's time to diet when you push away from the table and the table moves.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Date Timestamp Sort Problem (Excel 2003)

    How do you format the field in the query? By using the Format function? That converts the date/time value to a text string, so it will be sorted as text. If you use the Format property, the field should sort correctly.

  3. #3
    3 Star Lounger Omega3's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles, California, USA
    Posts
    343
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: Date Timestamp Sort Problem (Excel 2003)

    Thanks for your post. Yesterday was our holiday so this is the first chance I had to return your post. I did use the format function so that explains my problem. I forgot about the format property. I used that and it worked. Thanks!

    Now that it sorts properly and I removed the time, I took it a step further by making the query a Totals query grouped on the date field. Instead of grouping on the formated result it still grouped it on the underlying date/time stamp from the table. In fact, when you enter the cell of the resulting query you will still see the date/time. Making a second query based on this query would not work. What would be the best way to accomplish this, to create a totals query on a date and ignore the time?
    You know it's time to diet when you push away from the table and the table moves.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Date Timestamp Sort Problem (Excel 2003)

    You can use a calculated column

    Int([DateField])

    and format it as a date using the Format property. This will remove the time part from the date/timestamp. You should be able to use this column for sorting and grouping.

  5. #5
    3 Star Lounger Omega3's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles, California, USA
    Posts
    343
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: Date Timestamp Sort Problem (Excel 2003)

    Thank you Hans. Your solution worked.

    I take it that the "time" portion of the date/time field is stored as a decimal and the INT function uses only the integer (serial number of the date). I will have to remember that one for next time. Thank you very much for your help.
    You know it's time to diet when you push away from the table and the table moves.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Date Timestamp Sort Problem (Excel 2003)

    That's correct. Dates are stored as numbers with the date as the integer part (the number of days since December 31, 1899) and the time as the fractional part (e.g. 6:00 AM = 0.25 and 6:00 PM = 0.75).

  7. #7
    3 Star Lounger Omega3's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles, California, USA
    Posts
    343
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: Date Timestamp Sort Problem (Excel 2003)

    Thank you for confirming that for me. Have a wonderful day Hans!
    You know it's time to diet when you push away from the table and the table moves.

Posting Permissions

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