Answer the question
In order to leave comments, you need to log in
How to convert Russian time to datetime correctly?
Error when executing code
locale.setlocale(locale.LC_TIME, "ru_RU.UTF-8")
datetime.datetime.strptime('1 Декабрь 2019', '%d %B %Y').date()
ValueError: time data '1 Dec 2019' does not match format '%d %B %Y'
Answer the question
In order to leave comments, you need to log in
$db->query("INSERT INTO reg (vk_id, nfirst, nlast, bdate) VALUES ('$ids', '$first', '$last', '$bdate')");
$db->query("INSERT INTO reg (vk_id, nfirst, nlast, bdate) VALUES ('$ids', '$first', '$last', '$bdate')");
Changed a bit:
from datetime import datetime
RU_MONTH_VALUES = {
'Январь': 1,
'Февраль': 2,
'Март': 3,
'Апрель': 4,
'Май': 5,
'Июнь': 6,
'Июль': 7,
'Август': 8,
'Сентябрь': 9,
'Октябрь': 10,
'Ноябрь': 11,
'Декабрь': 12,
}
def int_value_from_ru_month(date_str):
for k, v in RU_MONTH_VALUES.items():
date_str = date_str.replace(k, str(v))
return date_str
date_str = int_value_from_ru_month('1 Декабрь 2019')
print (date_str)
d = datetime.strptime(date_str, '%d %m %Y')
print(d)
pip3 install dateparser
import dateparser
ruDate = '1 Декабрь 2019'
pyDate = dateparser.parse(ruDate)
print(pyDate)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question