Results 1 to 5 of 5
  1. #1
    James Parker is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Location
    Sacramento, CA
    Posts
    11

    How Do I Remove "Time" from a Datetime Field

    Problem: I run a query based on a table that defines the Data Type for this field as a datetime. The field is called "WHEN". I do not need the time, I only need the date.

    I do not know if the fix should be made only in the query, or if should and can be in the original table (Scrap_Q4).

    Here is the SQL for my query:
    SELECT Scrap_Q4.When, Scrap_Q4.REJ, Count(Scrap_Q4.PN) AS CountOfPN, Scrap_Q4.PN


    FROM Scrap_Q4
    GROUP BY Scrap_Q4.When, Scrap_Q4.REJ, Scrap_Q4.PN
    HAVING (((Scrap_Q4.When) Between [Start date] And [End date]) AND ((Scrap_Q4.REJ)=[#]))
    ORDER BY Scrap_Q4.When, Scrap_Q4.REJ;

    Obviously, I have many things going on in the query, but my goal right now is to just remove Time from the Date.

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    SELECT Format([DateFieldInTable],"mm-dd-yyyy") AS [YourDate]
    FROM [TableName];

  3. #3
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    . . . or . . . I could have just done it in YOUR query!!!

    Code:
     
    SELECT Format(Scrap_Q4.When,"mm-dd-yyyy"), Scrap_Q4.REJ, Count(Scrap_Q4.PN) AS CountOfPN, Scrap_Q4.PN
    FROM Scrap_Q4
    GROUP BY Scrap_Q4.When, Scrap_Q4.REJ, Scrap_Q4.PN
    HAVING (((Scrap_Q4.When) Between [Start date] And [End date]) AND ((Scrap_Q4.REJ)=[#]))
    ORDER BY Scrap_Q4.When, Scrap_Q4.REJ;

  4. #4
    James Parker is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Location
    Sacramento, CA
    Posts
    11

    Thumbs up

    Thanks Robeen. That was perfect. Made my day.

  5. #5
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    You can also change this:
    Format(Scrap_Q4.When,"mm-dd-yyyy")
    to
    Format(Scrap_Q4.When,"yyyy-mm-dd")

    When it comes to sorting dates in the mm-dd-yyyy format, I've had a couple of surprises because Access will put
    11-24-2011
    AFTER
    01-05-2012
    in an ASCENDING sort - because it evaluates the mm '11' as greater than the 01 . . . and doesn't seem to check for which year . . ..

    Of late, I've been putting my dates in yyyy-mm-dd format.

    All the best!!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 08-05-2011, 02:55 PM
  2. Replies: 16
    Last Post: 07-22-2011, 09:23 AM
  3. "Group By" causes "ODBC--Call Failed" error
    By kaledev in forum Queries
    Replies: 1
    Last Post: 03-09-2011, 02:43 PM
  4. Replies: 8
    Last Post: 11-12-2010, 10:55 AM
  5. Remove "-" from data
    By jgelpi16 in forum Queries
    Replies: 4
    Last Post: 03-22-2010, 10:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums