close

[Solved] Type: descriptor ‘strftime’ requires a ‘datetime.date’ object but received a ‘Text’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Type: descriptor ‘strftime’ requires a ‘datetime.date’ object but received a ‘Text’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Type: descriptor ‘strftime’ requires a ‘datetime.date’ object but received a ‘Text’ Error Occurs?

Today I get the following error Type: descriptor ‘strftime’ requires a ‘datetime.date’ object but received a ‘Text’ in python.

How To Solve Type: descriptor ‘strftime’ requires a ‘datetime.date’ object but received a ‘Text’ Error ?

  1. How To Solve Type: descriptor 'strftime' requires a 'datetime.date' object but received a 'Text' Error ?

    To Solve Type: descriptor 'strftime' requires a 'datetime.date' object but received a 'Text' Error You have a Text object. The strftime function requires a datetime object. The code below takes an intermediate step of converting your Text to a datetime using strptime

  2. Type: descriptor 'strftime' requires a 'datetime.date' object but received a 'Text'

    To Solve Type: descriptor 'strftime' requires a 'datetime.date' object but received a 'Text' Error You have a Text object. The strftime function requires a datetime object. The code below takes an intermediate step of converting your Text to a datetime using strptime

Solution 1

You have a Text object. The strftime function requires a datetime object. The code below takes an intermediate step of converting your Text to a datetime using strptime

import datetime
testeddate = '4/25/2015'
dt_obj = datetime.datetime.strptime(testeddate,'%m/%d/%Y')

At this point, the dt_obj is a datetime object. This means we can easily convert it to a string with any format. In your particular case:

dt_str = datetime.datetime.strftime(dt_obj,'%Y-%m-%d %H:%M:%S')

The dt_str now is:

'2015-04-25 00:00:00'

Solution 2

A less elegant solution would involve manipulating the string directly.

testeddate = '4/25/2015'
month, day, year = testeddate.split('/')
testeddate = '-'.join([year, month, day]) + ' 00:00:00'

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read