Results 1 to 4 of 4
  1. #1
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172

    Calculate number of days in the previous month

    Hi, I am trying to figure out how to create a field in my query that calculates the number of days in the previous month. I have been trying to use the DateSerial function, but can't get it to work. Does anyone have any suggestions?

    Kirsti

  2. #2
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    What I have so far is:

    DateDiff(“d”,DateSerial(Year(Now()),Month(Now()),1-1),DateSerial(Year(Now()),Month(Now())-1,1))

    But when I try and run it, I get 'Enter Parameter Value "d"'

  3. #3
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Strangely, when I went into the SQL view of the query and ran it, it ran without the 'Enter Parameter Value' error, and now it runs perfectly from any view.

    So, I have what I want!

  4. #4
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    One way could perhaps be :

    Code:
    SELECT 
        DateSerial(Year(Date()),Month(Date()),1)-1 AS TheLastDayOfThePreviousMonth, 
        DatePart("d",[TheLastDayOfThePreviousMonth]) AS TheNoOffDays;
    Another way, get the Last & 1st Date of the previous month & then use DateDiff().

    Edit : My typing speed.

    Thanks

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

Similar Threads

  1. Replies: 5
    Last Post: 04-01-2012, 07:21 AM
  2. Calculate Percentage based on previous column
    By VictoriaAlbert in forum Queries
    Replies: 1
    Last Post: 08-13-2011, 01:30 PM
  3. How to Calculate days of the week
    By djclntn in forum Database Design
    Replies: 3
    Last Post: 02-26-2011, 11:10 PM
  4. calculate no. of working days
    By JOSE LUIS in forum Access
    Replies: 1
    Last Post: 02-01-2010, 03:55 PM
  5. Total no of days in a month
    By wasim_sono in forum Forms
    Replies: 4
    Last Post: 10-15-2006, 01:05 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