core_lib.helpers.datetime_utils [source]
Core-Lib has various datetime utility functions that return datetime values in UTC. These functions will also set the returned value’s hour, minute, second and microsecond to 0 where ever necessary.
Functions
year_beginreturns the first day of the year.year_endreturns date when current year will end.month_beginreturns the first day of the current month.month_endreturns the last day of the month.week_beginreturns the first day of the week.Note: The starting day of the week will be considered as Monday.
week_endreturns the last day of the week.day_beginreturns thedatetimefor the beginning of the day.day_endreturns thedatetimefor the ending of the daytomorrowreturns tomorrow’s day.todayreturns today’s day.yesterdayreturns yesterday’s day.midnightreturns the midnight for today.sundayreturns the next Sunday’s date.mondayreturns the next Monday’s date.tuesdayreturns the next Tuesday’s date.wednesdayreturns the next Wednesday’s date.thursdayreturns the next Thursday’s date.fridayreturns the next Friday’s date.saturdayreturns the next Saturday’s date.hour_beginreturns the time for the beginning of current hour.hour_endreturns the time for the ending of current hour.agereturns age inintfor givendate.timestamp_to_msreturnstimestampconverted tomilliseconds.
Basic Usage
from core_lib.helpers.datetime_utils import year_begin
beginning_of_the_year = year_begin()
print(beginning_of_the_year) # will print "2022-01-01 00:00:00"
reset_datetime()
core_lib.helpers.datetime_utils.reset_datetime() [source]
Will reset the hour, minute, second and microsecond of a datetime value to 0
def reset_datetime(date: datetime):
Arguments
date(datetime): The DateTime to convert.
Returns
(datetime): Returns the DateTime with hour, minute, second and microsecond as 0.
Example
import datetime
from core_lib.helpers.datetime_utils import reset_datetime
formatted_datetime = reset_datetime(datetime.datetime.utcnow())
print(formatted_datetime) #2022-02-07 00:00:00