10 examples of 'python string to date yyyy-mm-dd' in Python

Every line of 'python string to date yyyy-mm-dd' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
48def convert2date(self, string):
49 try:
50 date = dateutil.parser.parse(string, default=self.default_date)
51 if date.year != 9999:
52 return date
53 except (ValueError, TypeError, OverflowError):
54 pass
254def date_str(s):
255 return datetime.datetime.strptime(s, '%Y-%m-%d').date()
68def date_to_str(date_str):
69 return date.strftime('%Y-%m-%d')
28def _parse_date(datestr):
29 return dateutil.parser.parse(datestr)
11def to_datetime(date_str: str) -> datetime:
12 d = date_str
13 try:
14 dte = datetime.strptime(d, "%Y-%m")
15 except ValueError:
16 dte = date_str
17 return dte
23def convert_date_format(self, str, format):
24 """
25 Convert date string to other format date string.
26 The converter parser is based on the specifications below.
27
28 https://dateutil.readthedocs.io/en/stable/parser.html
29
30 Args:
31 str: string before convert
32 format: formatter
33
34 Returns:
35 str: new format date string or None if str is None
36 """
37 if not str:
38 return None
39
40 p = parser.parse(str)
41 return p.strftime(format)
21def date(value, format='%Y-%m-%d'):
22 '''
23 >>> date('2000-01-01')
24 datetime.date(2000, 1, 1)
25 '''
26 return DateTime.strptime(value, format).date()
37def parseDate(date):
38 if isinstance(date, str):
39 try:
40 return duparser.parse(date)
41 except Exception:
42 pass
39def convert_date(date):
40 return datetime.datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ")
82def str_to_dt(date):
83 ''' Converts Yahoo Date Strings to datetime objects. '''
84 yr = int(date[0:4])
85 mo = int(date[5:7])
86 day = int(date[8:10])
87 return datetime.datetime(yr,mo, day)

Related snippets