useful snippets
General Info
Useful Snippets

14.0.4 Get the current date and time as a string

Description:

It's often handy to get the current time and date as a string so that you can use it in your program. For example, you may want to add a timestamp to the end of your filename to save when a file was created. Or, you may want to get the current timestamp as a string to use in a filter for a column in a dataframe.

Example:

from datetime import datetime

start_time_now = datetime.name()                         # get the current datetime timestamp
run_date = start_time_now.strftime("%Y%m%d")  # specify the date formating that you want
run_date = str(run_date)                                         # convert to a string