Extract month from Date

Hi
I am writing a server-script ( client side ) and want to extract the month from
a field called “from_date” and is of type “Date”.

So I need something like this …

from_date_month = extract_month(from_date)

from_date_month = 01 or 02 or 03 … or 12

I looked that the frappe methods but cannot see anything that will help me ?

You can try this

from datetime import datetime

def extract_months(doc):
    date_string =doc.date
    # Convert the date string to a datetime object
    date_object = datetime.strptime(str(date_string), '%Y-%m-%d')
    # Extract the month as an integer (1 for January, 12 for December)
    month = date_object.month

Thank you for your suggestion @saloni

I think my problem is, the fact that I am , just as an interim, writing
my code on a client-side server script of type API.

The idea is that, once the code is working, then I will port it to a true
server-side script.

I suspect that, in client-side server-script, I dont have access to
frappe.utils.datetime.strptime, becasue the error I am getting is …

Traceback (most recent call last): File "<serverscript>", line 31, in <module> TypeError: 'NoneType' object is not callable

Since I have sorted out the other functionality of the script, perhaps I should
move this to a proper server script.

Thank you for your time.

May I correct myself …
It was my (from_date) that was in the incorrect format !!!

Thank you for your time @saloni