You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to convert a date as a string into type date.
E.g: Oct 4 = ' 2015-10-04 00:00:00 '
I try this:
import parsedatetime as pdt
c = pdt.Constants()
p = pdt.Calendar(c)
f = '%Y-%m-%d %H:%M:%S'
data_format = p.parseDT(date_time) //In this case date_time= "Oct 4"
print data_format[0].strftime(f)
This code works, but strangely i see 2016 instead of 2015.
So I see this: ' 2016-10-04 00:00:00 '
The text was updated successfully, but these errors were encountered:
There is an option on Constants that allows you to interpret all dates without a year as relative to the current year. The default behavior is to assume that a date prior to today's date is referring to the following year.
Simply set the YearParseStyle to zero if you need this alternate behavior:
c.YearParseStyle=0
For example, with the default value c.YearParseStyle = 1, today (Oct 25, 2015) if I parsed Oct 26 I would get Oct 26, 2015. For Oct 24 I would get Oct 24, 2016. January 4 would of course also parse as 2016. With c.YearParseStyle = 0 all of these dates will parse as 2015.
I want to convert a date as a string into type date.
E.g: Oct 4 = ' 2015-10-04 00:00:00 '
I try this:
import parsedatetime as pdt
This code works, but strangely i see 2016 instead of 2015.
So I see this: ' 2016-10-04 00:00:00 '
The text was updated successfully, but these errors were encountered: