In my database I have a table holding some subscription information. I have among others a StartDate and an EndDate as DateTime.
What I need is to make a Linq query getting all rows due for payment. The payment is supposed to take place each month on the same day they registered (StartDate) and stop on the EndDate. So if they registered on the 23. May, I need to invoice them again 23. June, 23. July and so on.
var query = from c in db.Subscription
where c.StartDate.Value.Day == DateTime.Now.Day
// What if today is Feb. 28 and a customer registered January 31.
// What if....
I am lost…please help!
Best,
Jon 2H
Why don’t you create a seperate table for all due payments.
When a new subscription is taken out, you would calculate all future payment dates for that subscription, and add a number of rows into the DuePayments table with the SubscriptionID, PaymentDate & Amount.
The number of rows would equate to the number of months between the subscription start date and end date, and the payment dates could be easily calculated using DateTime.AddMonths(1) while less than end date.