Convert str to datetime

how to convert str to datetime in frappe as its not allowing me to import modules. can someone help me out with this.

@Rajath_Nair where ? client script ? server script ? backend files ?

Hi @Rajath_Nair

You can look in the base code of Frappe. How to import the datetime module.
https://github.com/search?q=repo%3Afrappe%2Ferpnext+import+datetime+language%3APython&type=code&l=Python

Thank You!

in api server script. i am receiving datetime in str and then trying to convert it to datetime for further operations.

@Rajath_Nair try this :
d=frappe.utils.getdate("01-01-2024")

2 Likes

can you also help me with how to check the datatype of the variable because type() is not working and in isinstance() i am unable to check the datatype.

@Rajath_Nair you can do a try exceptto see if the variable given through the api is valid or not , if it’s not you can throw an exception

thank you