How to get diff in seconds between two string datetime fields on server script

How can I get diff in seconds between two string datetime fields on server script. After this I want to use the method frappe.utils.format_duration() to get this different in a pretty way.

@heavyweb

 first_date=frappe.utils.get_datetime("2023-01-01")
 second_date=frappe.utils.get_datetime("2023-01-24")
 diff=frappe.utils.time_diff_in_seconds(second_date,first_date) 
 pretty=frappe.utils.format_duration(diff)
1 Like

A lot of thanks @bahaou. Works perfectly, just what I was looking for :slight_smile:

@heavyweb set answer as solution please

Sorry @bahaou I was searching how to do that and didn’t find it. Do you know how to do it?