Finding the last months start date given intial date in Python

dmontgom
dmontgom used Ask the Experts™
on
Hi,

Lets say my activation date is 1/8/2008 and will use this as the base date or billing date.

Given todays date, I need to find the last billing date.  So..if todays date is 10/20/09 the start of the current cycle is 10/8/09.  How do I find the current billing cycle taking into account year and month?  E.g. if the current date is 1/2/2009 I need to know that 12/08/2008 was the start of the last billing cycle.

Please show code.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
HonorGodSoftware Engineer

Commented:
What is the algorithm / recipe for determining the start of a billing cycle?

Author

Commented:
Take it as given. For different clients, the start date can be any month or any day.
HonorGodSoftware Engineer

Commented:
So, when you say that you want to "find the last billing date", given an input date of 10/20/2009 and a billing day of 8 (e.g, say you started your billing cycle on 1/8/2000), you want it to return 10/08/09, right?
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Software Engineer
Commented:
By that I mean, the most recently passed billing date.  Right?

Which should be as simple as:

If the specified day of month < billing day :
  if month == 1 :
    decrement the year
    month = 12
  else
   decrement the month
replace the day of the month with the billing cycle day

Right?

Commented:
How you want one-month-ago(31.mar.2006) or one-month-ago(28.feb.2006) to work?
Ie. when base date's day doesn't exist in the previous month?

Author

Commented:
Thanks
HonorGodSoftware Engineer

Commented:
Thanks for the grade & points.

Good luck & have a great day.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial