Created
February 18, 2022 04:49
-
-
Save Pradip-p/2082be7c21c2a40af17c192a695174a2 to your computer and use it in GitHub Desktop.
get get_current_date,get_day,get_month,get_year and get_time in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def get_current_date(format="%Y-%m-%d"): | |
""" | |
Returns the current date | |
:param format: desired Date format | |
examples: | |
%Y-%m-%d | |
%d-%m-%Y | |
%Y/%m/%d | |
:return: date string in the format specified. | |
Default format is YYYY-MM-DD | |
""" | |
return datetime.datetime.now().strftime(format) | |
def get_day(): | |
""" | |
returns current day | |
:return: int | |
""" | |
return datetime.datetime.now().day | |
def get_month(): | |
""" | |
returns current month | |
:return: int | |
""" | |
return datetime.datetime.now().month | |
def get_year(): | |
""" | |
Returns current year | |
:return: int | |
""" | |
return datetime.datetime.now().year | |
def get_time(format='%H:%M:%S'): | |
""" | |
Returns current time | |
:param format :desired time format | |
default = %H:%M:%S | |
examples: | |
%H-%M-%S | |
%H:%M: | |
:return: int | |
""" | |
return datetime.datetime.now().strftime(format) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment