convert str to datetime

51 views
Skip to first unread message

armagan

unread,
Jun 25, 2012, 8:42:27 AM6/25/12
to django...@googlegroups.com
Hi,

I'm trying to convert to str to datetime. "date object" must be datetime object. Can you help me?

 def item_pubdate(self, item): # Yayinlanma Tarihi

        if item.delivery_date:

            date = item.delivery_date

            dt = datetime.combine(date, time())

            return dt

        else:

            return ' '

Daniel Roseman

unread,
Jun 25, 2012, 9:01:08 AM6/25/12
to django...@googlegroups.com
No, we can't help you. What is `item.delivery_date`? What does `str` have to do with anything? What is the relevance of '"date object" must be datetime object' - is that an error message you are getting? If so, why don't you post the actual traceback, which is full of useful debugging information?
--
DR.

Melvyn Sopacua

unread,
Jun 25, 2012, 11:27:13 AM6/25/12
to django...@googlegroups.com
On 25-6-2012 10:42, armagan wrote:
> Hi,
>
> I'm trying to convert to str to datetime. "date object" must be datetime
> object. Can you help me?
>
> def item_pubdate(self, item): # Yayinlanma Tarihi
>
> if item.delivery_date:
>
> date = item.delivery_date
So, that's a string and you need it to be a date object. Where does the
string come from and what does it look like?
--
Melvyn Sopacua


armagan

unread,
Jun 25, 2012, 12:07:19 PM6/25/12
to django...@googlegroups.com
I don't know where does string come from. In shell date is a date object and combine time dt is a datetime objects. It's ok. But I run the code I have an errror. can't compare datetime.datetime to str. 

item = Project.objects.order_by('-create_date')[:20

delivery_date = models.DateField(_(u'Teslim Tarihi'), blank=True, null=True)

Daniel Roseman

unread,
Jun 25, 2012, 12:27:11 PM6/25/12
to django...@googlegroups.com
On Monday, 25 June 2012 13:07:19 UTC+1, armagan wrote:
I don't know where does string come from. In shell date is a date object and combine time dt is a datetime objects. It's ok. But I run the code I have an errror. can't compare datetime.datetime to str. 

item = Project.objects.order_by('-create_date')[:20

delivery_date = models.DateField(_(u'Teslim Tarihi'), blank=True, null=True)


At a guess, the string is coming from the string that you return if delivery_date is empty.
--
DR.
Reply all
Reply to author
Forward
0 new messages