Results 1 to 6 of 6
  1. #1
    lweinbrecht is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    1

    If statement that will return data based on the time of the day.

    Hello,

    I am trying to write an expression that will result in a date in the format (mm/dd/yyy). I want to display the curent day if it is before 11:00 am based on the system time, and the next day if it is after 11:00 am. Below is the expression that I currently am working with... but it is not working. Please help. LW

    IIf(Time()>Hour(11),Date(),DateAdd("d",1,Date()))

    ps. i might be going to the total wrong direction....

  2. #2
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Try this
    Code:
    IIf(Time()<#11:00:00 AM#,Date(),DateAdd("d",1,Date()))

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,628
    The Hour() usage doesn't make sense. Hour() is used to extract the hour from a valid date.

    IIf(Time()<"11:00:00 AM", Date(), Date() + 1)

    or

    Date() + IIf(Time()<"11:00:00 AM", 0, 1)


    Day is default unit when adding with date value so don't need DateAdd.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    June7 - Quite true, but I try to use DateAdd for any such thing, since MS Access can get quite finnicky at unpredictable times, and DateAdd is self documenting the next time I have to read my own code.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,628
    Good point, try:

    DateAdd("d", IIf(Time()<"11:00:00 AM", 0, 1), Date())
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Clean. Either #2 or #5 should get the correct result.

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

Similar Threads

  1. Query Sql IIf Statement return value
    By ice051505 in forum Queries
    Replies: 10
    Last Post: 03-07-2013, 03:20 PM
  2. Replies: 2
    Last Post: 03-07-2013, 03:14 PM
  3. Ordering data based on an iif statement?
    By TonyB in forum Programming
    Replies: 1
    Last Post: 12-07-2011, 05:53 AM
  4. Replies: 7
    Last Post: 08-03-2011, 08:00 AM
  5. Replies: 1
    Last Post: 04-15-2010, 02:07 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