Finding next month: Excel, Python

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
901
Hello the following returns "Feb 25"

today = datetime.datetime.today().date()
string_date = today.strftime("%b %y")

I now want to adapt so that it finds the next month from today, "Mar 25".

Any ideas, thanks.
 
Rich (BB code):
yourdate+relativedelta(months=1)

1740475320577.png

1740475395416.png
 
Upvote 0
Sorry forgot that you would need the dateutil module installed to use the above, I don't think there is an easy/accurate solution using standard Python
 
Upvote 0
Thanks Mark, how do you reference a cell, e.g. A1 within Python code?

So if I had Mar 25 in cell A1, so if I was able to put the text in bold in a cell?

today = datetime.datetime.today().date()
string_date = "Mar 25"
long_string_date = "March 2025"

Thanks.
 
Upvote 0
I have the following;

import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime
import datetime
import matplotlib.dates as mdates
import numpy as np
import matplotlib.ticker as plticker
from dateutil.relativedelta import relativedelta
import calendar
 
Upvote 0
Personally I would use openpyxl for cell manipulation (not that I would bother using Python for this)

Python:
# Create a Workbook
wb = Workbook()

# Get the work sheet
sheet = wb.active

# ...
from openpyxl.styles import Font


# ...
sheet['A1'].font = Font(
                      name='Calibri',
                      bold=True,
                      italic=True,
                      size=14,
                      color="FF6347"
                )
 
Last edited:
Upvote 0
Personally I would use Openpxl for cell manipulation (not that I would bother using Python for this)

Python:
# Create a Workbook
wb = Workbook()

# Get the work sheet
sheet = wb.active

# ...
from openpyxl.styles import Font


# ...
sheet['A1'].font = Font(
                      name='Calibri',
                      bold=True,
                      italic=True,
                      size=14,
                      color="FF6347"
                )
Thanks, why is the font critical?

All I need to do is pull the value in cell A1, which is Mar 25
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top