Results 1 to 6 of 6
  1. #1
    dave_282 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2016
    Posts
    8

    Calculate Dates


    Hello,

    I'm in the process of creating a new table in an access database for our team to add rows in, I have a date field but I want the date to be calculated automatically based on the current time of when a new record is entered. midnight to 6:59 am I want the date to be date -1 (yesterday) and 7am to 11:59pm to be current date.

    I've tried putting syntax into the default value bit but that's not working so not sure of either the syntax and where exactly in access to do this. Hoping its possible? Can anyone assist please?

  2. #2
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    =IIf(Hour(Now()<7),DateAdd("d",-1,Date()),Date())

  3. #3
    dave_282 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2016
    Posts
    8
    Thanks for that, I put that in the default value property of the date field, is that the correct place to put it? It appeared to work in that it gave me todays date when I went to create a new record in the table but I changed the time of my PC to before 7 and the date was still todays so I cant validate if its working or not?

  4. #4
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Yes, it's correct place and it should work (I didn't test it though).
    Actually I just realised that one bracket is in wrong place
    This is correct:
    =IIf(Hour(Now())<7,DateAdd("d",-1,Date()),Date())

  5. #5
    dave_282 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2016
    Posts
    8
    Brilliant, that's working, thanks a lot!

  6. #6
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Happy to help

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

Similar Threads

  1. Database that calculate Due Dates
    By wipidu in forum Access
    Replies: 5
    Last Post: 07-20-2014, 02:27 AM
  2. Calculate Minutes Between Two Dates and Times
    By robrich22 in forum Programming
    Replies: 3
    Last Post: 01-31-2014, 07:56 PM
  3. Calculate days between two dates by VBA
    By hhuuhn12 in forum Programming
    Replies: 16
    Last Post: 12-10-2013, 03:11 PM
  4. Calculate time between two working dates
    By Alprashant in forum Access
    Replies: 15
    Last Post: 10-10-2013, 03:19 PM
  5. Calculate duration between two dates
    By Tommy1005 in forum Queries
    Replies: 3
    Last Post: 07-02-2012, 05:41 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