Results 1 to 14 of 14
  1. #1
    d3pl0y3d is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Location
    Ft Sill, OK
    Posts
    12

    counting days

    Basically, I have two colums with dates. A from date, and a to date. I'm just tryin to make the next colum count the ammount of days from the from date to the to date. It has to count the actual day it starts and ends too though, so whatever it comes up with will probably have to have 1 day added to it. so if I'm taking from the 23rd to the 25th, that's 3 days, not 2. I'm pretty sure most formulas or tracking systems that people use would count it as 2. I hope I'm expressing what I'm trying to do in a way that is understandable.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use the DateDiff() function to count the days, adding 1 if necessary. More info on that function in Help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you tried the DateDiff() function yet?

  4. #4
    d3pl0y3d is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Location
    Ft Sill, OK
    Posts
    12
    It comes up looking like this: DateDiff («interval», «date1», «date2», «firstweekday», «firstweek») I don't know how to write it though. interval needs to be by days, but when I replace it with d or (d), it says it doesn't recognize that field.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    DateDiff("d", Now, TheDate)

  6. #6
    d3pl0y3d is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Location
    Ft Sill, OK
    Posts
    12
    type mismatch in the default value??

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Are your two fields DateTime DataTypes? What are their names? Show us what you have.

  8. #8
    d3pl0y3d is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Location
    Ft Sill, OK
    Posts
    12
    ok, got it past that message, now it's saying it doesn't recognize the field "From" in a valid expression, or the default value in the table "Cadre Leave"

    the two fields are From and To, they're both date/time types the table is named Cadre Leave.
    I'm entering DateDiff("d",From,To) into default value, it turns it into DateDiff("d",[From],[To]) when I go to save it, I get the message I mentioned at the start of this reply

  9. #9
    d3pl0y3d is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Location
    Ft Sill, OK
    Posts
    12
    The field that it's going into is labeled Days, and I have it as a number type field

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You should *always* adjust your names to not conflict with RESERVED words. They can cause you no end of grief. http://www.allenbrowne.com/AppIssueBadWord.html#F

  11. #11
    d3pl0y3d is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Location
    Ft Sill, OK
    Posts
    12
    Changed them to From - Sign out, To - Sign in, Days - Total... same thing, except it says Sign out in the message now instead of From

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You should also not embed spaces in any names. I use CamelFontNames for clarification. Where are you putting this code? On a form? In a query?

  13. #13
    d3pl0y3d is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Location
    Ft Sill, OK
    Posts
    12
    I'm putting it in default value in the field property for a column in a database table

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I don't think that will work and calculated fields should be in queries and not tables.

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

Similar Threads

  1. No activity in last 30 days
    By CMLS in forum Queries
    Replies: 4
    Last Post: 03-18-2011, 11:26 AM
  2. Select Dates between days and two days ago?
    By rstonehouse in forum Queries
    Replies: 4
    Last Post: 08-18-2010, 02:13 AM
  3. Travel days.
    By emccalment in forum Access
    Replies: 1
    Last Post: 01-06-2010, 05:39 PM
  4. Replies: 4
    Last Post: 08-27-2009, 01:21 AM
  5. less than 180 days old
    By techexpressinc in forum Queries
    Replies: 2
    Last Post: 06-04-2009, 04:29 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