0

Hello i'm using the ParseDateTime lib in order to convert from natural text like "3 day ago" into a simple data string.

I use this code:

 import parsedatetime as pdt # $ pip install parsedatetime
 import datetime
 c = pdt.Constants()
 p = pdt.Calendar(c)
 output=p.parse(input_data)

my output is:

(time.struct_time(tm_year=2015, tm_mon=10, tm_mday=17, tm_hour=1, tm_min=42, tm_sec=15, tm_wday=5, tm_yday=290, tm_isdst=-1),
           1)

There is a way to have DD/MM/YYYY easy string?

RedVelvet
  • 1,683
  • 3
  • 15
  • 24

1 Answers1

1

As of version 1.5 of parsedatetime method Calendar.parse() returns a tuple. More precisely, a tuple with an inner tuple which is actually the parsed datetime. To get an ordinary datetime object you should use parseDT() method of the same class:

d = p.parseDT("2015/10/11 12:24")
d[0].strftime("%d/%m/%Y")
user3159253
  • 16,836
  • 3
  • 30
  • 56