Results 1 to 7 of 7
  1. #1
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2003
    Join Date
    Sep 2013
    Posts
    287

    Remove time from date/time field and be able to search with date criteria

    Hey guys,

    I have a problem, which I really feel like I shouldn't be having. There is a field, [DateChanged], in my ODBC database. It is a date/time field. I don't need the time, and I search with date-only ranges, so I really need to remove the time part. Everything that I have searched has come up with 2 options.



    1. Use DateValue([DateChanged])
    2. Use format([DateChanged],"mm/dd/yyyy")

    When using DateValue, if I search for #4/17/16# (with or without the #) I get the "expression is too complicated" error.

    When using Format(), if I search for #4/17/16# (with or without the #) I get no results.

    I am 100% stumped on what is going on, or what I am doing wrong. I appreciate any help.

    If it makes a difference, the end goal is to be able to use this criteria in the final query: Between [Forms]![F_Switchboard]![DateFrom] And [Forms]![F_Switchboard]![DateTo]

    Both of those date fields are stored as text, and work great everywhere else I use that statement.

    Click image for larger version. 

Name:	Screen Shot 2016-04-19 at 2.14.32 PM.png 
Views:	8 
Size:	24.4 KB 
ID:	24385

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2013
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Is the original value of the Date Time field also text? If not, then in the datevalue field, try =Int(Original) and format as desired.

  3. #3
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2003
    Join Date
    Sep 2013
    Posts
    287
    No, sir. It is a Date/Time value. Click image for larger version. 

Name:	Screen Shot 2016-04-19 at 3.14.44 PM.png 
Views:	8 
Size:	18.5 KB 
ID:	24386

  4. #4
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2013
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    If date/Time, then use my suggestion above. =Int(fieldName) and format as required.

    Look at this link at how dates and times are stored in Excel. It is similar in Access http://www.cpearson.com/excel/datetime.htm

  5. #5
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2003
    Join Date
    Sep 2013
    Posts
    287
    Click image for larger version. 

Name:	Screen Shot 2016-04-19 at 3.45.47 PM.png 
Views:	8 
Size:	7.1 KB 
ID:	24388

    Int([field]) gave me a integer value. Datevalue(Int([field])) gave me a correct looking date. Using #4/17/16# as criteria gives the "too complex" error again.

  6. #6
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2013
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Format the integer value as a Date. Here is an explanation on how dates are stored in Access.

    Access stores the Date/Time data type as a double-precision, floating-point number up to 15 decimal places. The integer part of the double-precision number represents the date. The decimal portion represents the time.

    Valid date values range from -657,434 (January 1, 100 A.D.) to 2,958,465 (December 31, 9999 A.D.). A date value of 0 represents December 30, 1899. Access stores dates before December 30, 1899 as negative numbers.

    Valid time values range from .0 (00:00:00) to .99999 (23:59:59). The numeric value represents a fraction of one day. You can convert the numeric value to hours, to minutes, and to seconds by multiplying the numeric value by 24.

  7. #7
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2003
    Join Date
    Sep 2013
    Posts
    287
    Nulls If I put an Is Not Null in there, all is peachy. Using Cdate(int([field]))

    Thanks for the help!

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

Similar Threads

  1. Replies: 7
    Last Post: 09-02-2014, 08:18 AM
  2. Replies: 11
    Last Post: 07-20-2014, 06:22 PM
  3. Subtracting a date/time field from a number to get date/time
    By Lifeseeker1019 in forum Programming
    Replies: 4
    Last Post: 03-28-2014, 12:59 PM
  4. Replies: 5
    Last Post: 03-19-2014, 02:31 PM
  5. Replies: 1
    Last Post: 03-13-2014, 07:23 PM

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