Saturday, January 28, 2017

More Operations on datetime :)

Tags

Suppose we want to Display only current Month, Year or Day. Python allows us to do this through some predefined Functions.
Following Program Illustrates it:

from datetime import datetime
current=datetime.now(); #assigning variable
print(current.year);    #Current year
print(current.month);    #Current month
print(current.day);    #Current date




Functions for Time:

print(current.hour);    #Current Hour
print(current.minute);    #Current Minute
print(current.second);    #Current Second