Results 1 to 8 of 8
  1. #1
    silverxx12 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    18

    last date

    Hi

    In my query i have various dates in a given month eg mar is it possible to create a function / expression which will give me the last date of the month ?

    so my query would look like ?

    Preferably without the use of vba as i am not too familiar with it?



    26/3/12 - 31/3/12
    24/3/12 - 31/3/12


    many thanks

  2. #2
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Just check if below gives some guidelines :

    Code:
    SELECT 
    	tblDates.testDate, 
    	DateSerial(Year([testDate]),Month([testDate])+1,1) AS NextMonthDate, 
    	DateAdd("d",-1,[NextMonthDate]) AS LastDateOfMonth
    FROM 
    	tblDates;
    Thanks

  3. #3
    silverxx12 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    18
    hi for some reason it does not like the syntax keep on getting an error:

    could you possibly explain what the formula is doing maybe i am inputting something incorrectly ?

  4. #4
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    what error ?
    Can you show us the sql.

    The input date
    Code:
    SELECT 
     tblDates.testDate,
    This should get the 1st Date of the next month
    Code:
    DateSerial(Year([testDate]),Month([testDate])+1,1) AS NextMonthDate,
    This should subtract 1 day from the Next month 1st Date to get the last day of the month
    Code:
    DateAdd("d",-1,[NextMonthDate]) AS LastDateOfMonth
    Code:
    FROM 
        tblDates;
    Thanks

  5. #5
    silverxx12 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    18
    ok finally got it to work :

    i guess i had a couple of issues when copy and replacing code mainly and some wierd characters appearing from "word".

    basically the formula gives two outputs, correct? The next month and the day before the next month clever...:-)

    The next issue i am having is now i have three columns with dates - the current date of the data the next months date and last date of the month

    is there a way to only show the last date of the month without the previous two columns showing ? i tried unchecking the expression in design view but the results cased the last date of the month to disappear?

    many thanks for the help so far

  6. #6
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Just check out if below gives some guidelines :
    Code:
    SELECT 
        tblDates.testDate, 
        DateSerial(Year([testDate]),Month([testDate])+1,1) AS NextMonthDate, 
        DateAdd("d",-1,[NextMonthDate]) AS LastDateOfMonth
    FROM tblDates;
    Code:
    SELECT 
        tblDates.testDate, 
        DateAdd("d",-1,DateSerial(Year([testDate]),Month([testDate])+1,1)) AS LastDateOfMonth
    FROM tblDates;
    Code:
    SELECT 
        DateAdd("d",-1,DateSerial(Year([testDate]),Month([testDate])+1,1)) AS LastDateOfMonth
    FROM tblDates;
    Thanks

  7. #7
    silverxx12 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    18
    ty works perfectly!!

  8. #8
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    H2H - Happy To Help

    Thanks

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

Similar Threads

  1. Replies: 12
    Last Post: 04-26-2012, 04:01 AM
  2. Replies: 15
    Last Post: 04-06-2012, 10:57 AM
  3. Replies: 3
    Last Post: 04-01-2012, 01:40 PM
  4. Replies: 1
    Last Post: 12-12-2011, 06:32 AM
  5. Replies: 1
    Last Post: 07-07-2010, 04:22 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