Equivalent function of MatLab's "dateshift(...)" in Python?
<p>MatLab can take a date and move it to the end of the month, quarter, etc. using the <code>dateshift(...)</code> <a href="https://www.mathworks.com/help/matlab/ref/dateshift.html" rel="nofollow">function</a>.</p>

<p>Is there an equivalent function in Python?</p>

<p>I think <code>calendar.monthrange</code> should do it for you, e.g.:</p>

<pre><code>&gt;&gt;&gt; import datetime, calendar
&gt;&gt;&gt; year = int(input("Enter year: "))
Enter year: 2012
&gt;&gt;&gt; month = int(input("Enter month: "))
Enter month: 3
&gt;&gt;&gt; endOfMonthDate = datetime.date(year, month, calendar.monthrange(year, month)[1])
&gt;&gt;&gt; endOfMonthDate
datetime.date(2012, 3, 31)
&gt;&gt;&gt; 
</code></pre>

<p>You might find other helpful functions here: <a href="https://docs.python.org/2/library/calendar.html" rel="nofollow">https://docs.python.org/2/library/calendar.html</a> and here: <a href="https://docs.python.org/2/library/datetime.html" rel="nofollow">https://docs.python.org/2/library/datetime.html</a></p>

python matlab date