Results 1 to 2 of 2
  1. #1
    ccordner is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    65

    Date functions in a query

    Hi, think this is pretty simple but I can't work it out.



    I want two expressions in a query.

    One to work out the Sunday before the first day of the month (or the first day of the month if it was a Sunday.

    The other to work out the last day of the year.

    Any ideas?

    Thanks
    Chris

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Well, the last day of the year is easy:

    LastDay:Format(DateSerial(Year(Date()), 12, 31), "dddd")

    As for the Sunday before the first day of the month you can paste this code into a STANDARD Module (name the module something other than the name of the function):
    Code:
    'Code courtesy of Bob Askew (raskew on Access World Forums)
    Function GetPrevSunday(dteDate As Date) As Date
        GetPrevSunday = DateAdd("d", -Weekday(dteDate) + 1, dteDate)
    End Function
    and then call it in your query:
    MySunday:GetPrevSunday(DateSerial(Year(date()), Month(Date()),1))

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

Similar Threads

  1. Replies: 0
    Last Post: 07-13-2011, 08:32 AM
  2. Replies: 5
    Last Post: 03-10-2011, 02:19 PM
  3. using Functions to validate a date field
    By jamin14 in forum Programming
    Replies: 1
    Last Post: 03-18-2010, 12:46 PM
  4. Replies: 1
    Last Post: 12-11-2008, 01:28 PM
  5. Functions in Query Criteria
    By hraup in forum Queries
    Replies: 1
    Last Post: 10-06-2006, 06:41 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