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:
get_current_date()
get_current_datetime()
get_current_time()
get_custom_datetime(format='YYYY-MM-DD HH:mm:ss')
get_date_from_datetime(datetime)
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:
get_time_from_datetime(datetime)
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: