Answered by : juan-david-morales-navarrete
import datetime
t = datetime.datetime(2012, 2, 23, 0, 0)
t.strftime('%m/%d/%Y')
Source : https://stackoverflow.com/questions/10624937/convert-datetime-object-to-a-string-of-date-only-in-python | Last Update : Thu, 17 Mar 22
Answered by : softhunt
# import the date class
from datetime import date
# function of date class
today = date.today()
# Converting the date to the string
Str = date.isoformat(today)
print("String Representation", Str)
print(type(Str))
Source : https://softhunt.net/python-datetime-with-6-main-classes-and-examples/ | Last Update : Mon, 06 Jun 22
Answered by : softhunt
# Python program to demonstrate datetime object
# import datetime class
from datetime import datetime as date
# Getting current date and time
now = date.now()
string = date.isoformat(now)
print(string)
print(type(string))
Source : https://softhunt.net/python-datetime-with-6-main-classes-and-examples/ | Last Update : Mon, 06 Jun 22
Answered by : powerful-partridge-sej1tn11ho58
from datetime import datetime
now = datetime.now() # current date and time
year = now.strftime("%Y")
print("year:", year)
month = now.strftime("%m")
print("month:", month)
day = now.strftime("%d")
print("day:", day)
time = now.strftime("%H:%M:%S")
print("time:", time)
date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
print("date and time:",date_time)
Source : https://www.programiz.com/python-programming/datetime/strftime | Last Update : Thu, 31 Mar 22
Answered by : akintunde-i-makinde
# You can use Numpy's datetime_as_string function.
# The unit='D' argument specifies the precision, in this case days.
t = numpy.datetime64('2012-06-30T20:00:00.000000000-0400')
numpy.datetime_as_string(t, unit='D')
Source : https://stackoverflow.com/questions/19502506/convert-numpy-datetime64-to-string-object-in-python | Last Update : Sun, 08 May 22