Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

ms access - Create a date table between 2 dates

I am a newbie in programming and trying to add some automation in my team to help with daily operation.

I try to create a function to create interest payment schedule according to given start date, end date and intervals. For example, for a one-year security with start date 2017/01/14, maturity date 2018/01/14, payment frequency is every 3 months. it has 4 interest period: 2017/01/14 - 2017/04/14, 2017/04/14 - 2014/07/14, 2017/07/14 - 2017/10/14, 2017/10/14 - 2018/01/14. I want to create a date table to display these 4 periods in Access.

The record should look like below:

seq startdate enddate

1       2017/01/14  2017/04/14
2       2017/04/14  2017/07/14
3       2017/07/14  2017/10/14
4       2017/10/14  2018/01/14

Could anyone help me with this? Thanks a lot.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the MSysObjects table and a Cartesian query to create this:

PARAMETERS 
    Period Text ( 255 ), 
    Periods Short, 
    FirstDate DateTime;
SELECT DISTINCT 
    10*Abs([Deca].[id] Mod 10)+Abs([Uno].[id] Mod 10)+1 As Sequence,
    DateAdd([Period],[Sequence]-1,[FirstDate]) AS [DateStart],
    DateAdd([Period],[Sequence],[FirstDate]) AS [DateEnd]
FROM 
    MSysObjects AS Uno, 
    MSysObjects AS Deca
WHERE 
    10*Abs([Deca].[id] Mod 10)+Abs([Uno].[id] Mod 10)<[Periods]

Run this with the parameters:

Period: q
Periods: 4
FirstDate: 2017-04-14

Result


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...