Results 1 to 5 of 5
  1. #1
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295

    Using time functions

    Good Day all,



    I am trying to create a time monitor that records when a worker is late or early.

    The schedule time of arrival is in a control "Schedule_Time" on the form
    I am using the time of arrival as the now() function.
    The worker is given a 15 minutes allowance on the schedule time of arrival

    To compare the times for late or early conditions this is my code:

    If Now() < Me.Shedule_Arrival + 15 Then
    MsgBox "I am Late"
    Else
    MsgBox "I am Early"
    End If

    I am not getting the expected results even when I wrap the function with timeValue like so:

    If TimeValue(Now()) < timeValue(Me.Shedule_Arrival) + 15 Then
    MsgBox "I am Late"
    Else
    MsgBox "I am Early"
    End If

    I would be grateful for an explanation

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    in access, time math is done with DATEDIFF, DATEADD
    so
    If Now() < dateAdd(15,"n",Shedule_Arrival) Then

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    From Access HELP:

    Date Data Type
    Date variables are stored as IEEE 64-bit (8-byte) floating-point numbers that represent dates ranging from 1 January 100 to 31 December 9999 and times from 0:00:00 to 23:59:59.

    When other numeric types are converted to Date, values to the left of the decimal represent date information while values to the right of the decimal represent time. Midnight is 0 and midday is 0.5. Negative whole numbers represent dates before 30 December 1899.

    So when you entered
    If Now() < Me.Shedule_Arrival + 15 Then
    you were saying "Add 15 DAYS to the control named Me.Shedule_Arrival.

    To add 15 MINUTES, you would add a value of approx. 0.0104.

    Your code would be
    Code:
    If Now() < Me.Shedule_Arrival + 0.0104 Then
        MsgBox "I am Early"
        Else
        MsgBox "I am Late"
      End If
    But would need to swap the true and false responses. (see above)


    You could use:
    Code:
        Dim ClockedIn As Date
        ClockedIn = Now()
    
    
        Select Case ClockedIn
    
            Case Is < Me.Shedule_Arrival
                MsgBox "I am Early"
            Case Me.Shedule_Arrival To (Me.Shedule_Arrival + 0.0104)
                MsgBox "I am On Time"
            Case Is > (Me.Shedule_Arrival + 0.0104)
                MsgBox "I am Late"
        End Select

  4. #4
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    This was a long challenging day with a very steep learning curve; but I made it. Thanks very much for the introduction of these functions.

  5. #5
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    Quote Originally Posted by ranman256 View Post
    in access, time math is done with DATEDIFF, DATEADD
    so
    If Now() < dateAdd(15,"n",Shedule_Arrival) Then
    This was a long challenging day with a very steep learning curve; but I made it. Thanks very much for the introduction of these functions.

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

Similar Threads

  1. Replies: 1
    Last Post: 05-21-2016, 08:51 AM
  2. Functions
    By gelabelle in forum Modules
    Replies: 2
    Last Post: 11-11-2015, 11:53 PM
  3. Replies: 42
    Last Post: 03-01-2013, 06:58 AM
  4. Date/Time Functions
    By Cybercow in forum Code Repository
    Replies: 1
    Last Post: 11-22-2012, 09:30 AM
  5. F functions
    By dref in forum Access
    Replies: 1
    Last Post: 08-23-2012, 06:13 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