Skip to content

Dates

Dates module for autopylot. This module is used to interact with dates.

Examples:

>>> from autopylot import dates
>>> dates.get_current_date()
'2020-12-31'
>>> dates.get_current_time()
'23:59:59'
>>> dates.get_current_datetime()
'2020-12-31 23:59:59'
>>> dates.add_days(date='2020-12-31', days=1)
'2021-01-01 00:00:00'
>>> dates.add_months(date='2020-12-31', months=1)
'2021-01-31 00:00:00'

It contains the following functions:

  • get_current_date(): Get the current date.
  • get_current_time(): Get the current time.
  • get_current_datetime(): Get the current datetime.
  • get_custom_datetime(format): Get the current datetime with a custom format.
  • add_time(datetime, seconds, minutes, hours, days, months, years): Add time to a datetime.
  • subtract_time(datetime, seconds, minutes, hours, days, months, years): Subtract time from a datetime.
  • get_datetime_difference(start, end): Get the difference between two datetimes.
  • get_date_from_datetime(datetime): Get the date from a datetime.
  • get_time_from_datetime(datetime): Get the time from a datetime.

add_time(datetime, seconds=0, minutes=0, hours=0, days=0, months=0, years=0)

Add time to a datetime.

Parameters:

Name Type Description Default
datetime str

The datetime.

required
seconds int

The seconds to add.

0
minutes int

The minutes to add.

0
hours int

The hours to add.

0
days int

The days to add.

0
months int

The months to add.

0
years int

The years to add.

0

Returns:

Name Type Description
Date str

The datetime with the time added.

Examples:

>>> dates.add_time(date='2020-12-31 23:59:59', seconds=1)
'2020-12-31 23:59:59'

get_current_date()

Get the current date.

Returns:

Name Type Description
Date str

The current date.

Examples:

>>> dates.get_current_date()
'2020-12-31'

get_current_datetime()

Get the current datetime.

Returns:

Name Type Description
Date str

The current datetime.

Examples:

>>> dates.get_current_datetime()
'2020-12-31 23:59:59'

get_current_time()

Get the current time.

Returns:

Name Type Description
Date str

The current time.

Examples:

>>> dates.get_current_time()
'23:59:59'

get_custom_datetime(format='YYYY-MM-DD HH:mm:ss')

Get the current datetime.

Parameters:

Name Type Description Default
format str

The format of the datetime.

'YYYY-MM-DD HH:mm:ss'

Returns:

Name Type Description
Datetime str

The current datetime.

Examples:

>>> dates.get_custom_date_time(format='MM-DD-YYYY')
'12-31-2020'

get_date_from_datetime(datetime)

Get the date from a datetime.

Parameters:

Name Type Description Default
datetime str

The datetime.

required

Returns:

Name Type Description
Date str

The date.

Examples:

>>> dates.get_date_from_datetime(datetime='2020-12-31 23:59:59')
'2020-12-31'

get_datetime_difference(start, end)

Get the difference between two datetimes.

Parameters:

Name Type Description Default
start str

The first datetime.

required
end str

The second datetime.

required

Returns:

Name Type Description
Difference int

The difference between the datetimes in seconds.

Examples:

>>> dates.get_datetime_difference(start='2020-12-31 23:59:59', end='2021-01-01 00:00:00')
1

get_time_from_datetime(datetime)

Get the time from a datetime.

Parameters:

Name Type Description Default
datetime str

The datetime.

required

Returns:

Name Type Description
Date str

The time.

Examples:

>>> dates.get_time_from_datetime(datetime='2020-12-31 23:59:59')
'23:59:59'

subtract_time(datetime, seconds=0, minutes=0, hours=0, days=0, months=0, years=0)

Subtract time from a datetime.

Parameters:

Name Type Description Default
datetime str

The datetime.

required
seconds int

The seconds to subtract.

0
minutes int

The minutes to subtract.

0
hours int

The hours to subtract.

0
days int

The days to subtract.

0
months int

The months to subtract.

0
years int

The years to subtract.

0

Returns:

Name Type Description
Date str

The datetime with the time subtracted.

Examples:

>>> dates.subtract_time(datetime='2020-12-31 23:59:59', seconds=1)
'2020-12-31 23:59:59'