Dates ( pi-Day )
Question: I think everyone kwows when it's pi-Day (If you don't know it's on 14 March
each year). When you have a result in python like:

    
    
    (2016, 4, 4)
    

(This stands for the April 4, 2016). How can I find in a fast way when it's
the next pi-Day. In this example the answer would be:

    
    
    (2017, 3, 14)
    

Is there any formula I can use? Many thanks!


Answer: Using the [`datetime` module](https://docs.python.org/2/library/datetime.html)
you'd:

  1. Get todays date
  2. Get this years Pi-day (take the year from today's date)
  3. If this date is in the past, add one year

In code:

    
    
    from datetime import date
    
    def next_pi_date():
        today = date.today()
        pi_date = date(today.year, 3, 14)
        if pi_date < today:
            pi_date = pi_date.replace(year=pi_date.year + 1)
        return pi_date
    

Demo:

    
    
    >>> from datetime import date
    >>> def next_pi_date():
    ...     today = date.today()
    ...     pi_date = date(today.year, 3, 14)
    ...     if pi_date < today:
    ...         pi_date = pi_date.replace(year=pi_date.year + 1)
    ...     return pi_date
    ... 
    >>> next_pi_date()
    datetime.date(2015, 3, 14)
    

