Get Current Date and Time as String
Fetches the current date and time as a formatted string.
- datetime
- current
- string
Code
from datetime import datetime
def get_current_datetime_string():
return datetime.now().strftime('%Y-%m-%d %H:%M:%S')Usage
get_current_datetime_string() # Returns: '2023-01-01 12:00:00'