Addition of date and time

Hello,

May I know how to use below function in Server Script?

I want to combine date and time.

datetime = datetime.datetime.combine(date, time)

Like in shift_type.py, timedelta used.

out_time < logs[0].shift_end - timedelta(minutes=cint(self.early_exit_grace_period))

Or May I know how to add time in minutes to date?

Thanks

@umarless Try this…

import frappe
from frappe.utils import add_to_date, now

Current date and time

current_datetime = now()

Add 30 minutes to the current date and time

new_datetime = add_to_date(current_datetime, minutes=30)

print(“Current Date and Time:”, current_datetime)
print(“New Date and Time (after adding 30 minutes):”, new_datetime)

Thank you

1 Like

Thanks @Kiranmai

Is there any utility for format duration as hh:mm:ss like in below example format is “2h 46m 60s”

from frappe.utils import format_duration

format_duration(50) # '50s'
format_duration(10000) # '2h 46m 40s'
format_duration(1000000) # '11d 13h 46m 40s'

# Convert days to hours
format_duration(1000000, hide_days=True) # '277h 46m 40s'

@umarless

Frappe framework does not have a specific utility function for directly formatting durations as ‘hh:mm:ss’. Instead, it provides various utilities for obtaining time along with the date.

Have look on Frappe Utility Functions for reference.

Thank you

1 Like