View Full Version : post dates


deekras
07-02-2001, 07:30 PM
i am looking to make statements. i have a few different dates i need the program to figure out.

firstly, a person can be billed for 1,2,3 or 6 months at a time. that info will be in the table as numbers.
i want the program to figure out the effective dates, ie: if he is billed for 1 month at atime i want the program to say
July 1, 2001 - August 1, 2001. If he is billed for 2 months, it should say July 1, 2001 - September 1, 2001. etc.

i cannot write an if statement saying if [pmt]=1,then days = 30, because some months have more or less than 30 days.

i want the computer to figure out what is 1 or 2 months into the future. and write it out as words, not numbers.

any suggestions?

Pat Hartman
07-03-2001, 12:43 PM
I don't have time to write the code for you but basically you should create a function in a standard code module that you will call from a query. The function should take the base date and billing period as input and return the through date. In the function, use the DateAdd() function with the month option to add the number passed as billing period to the date that was passed. So, if the base date is Jan 13, 2001 and the billing period is 6, the function would add 6 months to the base date using the DateAdd() function and return July 13, 2001 as the result.

I believe the DateAdd() function adjusts for different month lengths so if your base month has more days than the result month, I think you will just get the last day of the month. So Jan 31 + 1 month = Feb 28. Test this to make sure.

You control how the date is displayed via the Format property or by using the Format() function.

To referenct your function in a query -

Select DateA, CalcDateB(DateA, BillingPeriod) As DateB
From YourTable;