Return a date object for a string "YYYYMMDD".
169431
def DateStringToDateObject(date_string):
  """"""
  # If this becomes a bottleneck date objects could be cached
  if re.match('^\d{8}$', date_string) == None:
    return None
  try:
    return datetime.date(int(date_string[0:4]), int(date_string[4:6]),
                         int(date_string[6:8]))
  except ValueError:
    return None
499448
def string2time(text):
    """"""
    length = len(TIME_FORMAT)
    result = None
    while length:
        try:
            result = datetime.strptime(text, TIME_FORMAT[:length])
        except:
            length -= 1
        else:
            break
    return result
311688
def format_date(date):
        
        # Handle time typing
        try:
            date = date.isoformat()
        except AttributeError:  # Not a datetime object
            date = str(date)

        date = parser.parse(date).strftime('%Y-%m-%d')
        return date
1315255
def t_DATE(t):
    '
    day = int(t.lexer.lexmatch.group('day'))
    month = int(t.lexer.lexmatch.group('month'))
    year = int(t.lexer.lexmatch.group('year'))
    t.value = date(year, month, day)
    return t
751256
def _x_format(self):
        """"""

        def date_to_str(x):
            d = datetime.utcfromtimestamp(x).date()
            return self.x_value_formatter(d)

        return date_to_str
1285525
function yyyymmddDateFromMonthDayYearDate(monthDayYearDate) {
	var yyyy = monthDayYearDate.split(',')[1].trim();
	var dd = monthDayYearDate.split(' ')[1].split(',')[0];
	var mm = '';
	switch (monthDayYearDate.split(' ')[0]) {
		case 'January': 
			mm = '01';
			break;
		case 'February':
			mm = '02';
			break;
		case 'March':
			mm = '03';
			break;
		case 'April':
			mm = '04';
			break;
		case 'May':
			mm = '05';
			break;
		case 'June':
			mm = '06';
			break;
		case 'July':
			mm = '07';
			break;
		case 'August':
			mm = '08';
			break;
		case 'September':
			mm = '09';
			break;
		case 'October':
			mm = '10';
			break;
		case 'November':
			mm = '11';
			break;
		case 'December':
			mm = '12';
			break;
	}
	return yyyy + '-' + mm + '-' + dd;
}
988125
def _parse_date(self, date_string):
        """"""
        date = datetime.strptime(date_string, self._DATE_FORMAT)
        self.date = self._TZ.localize(date).astimezone(pytz.UTC)
700394
def str_to_date(date: str) -> datetime.datetime:
    
    date = date.split('.')
    date.reverse()
    y, m, d = date
    return datetime.datetime(int(y), int(m), int(d))
1293722
def str2dt(s):
    """"""
    return datetime.datetime.strptime(s, _FMTS if s.count(":") == 2 else _FMT if s.count(":") == 1 else _FMT0)
1203908
def date_cast(date):
    '''
    
    '''
    if date is None:
        return datetime.datetime.now()
    elif isinstance(date, datetime.datetime):
        return date

    # fuzzy date
    try:
        if isinstance(date, six.string_types):
            try:
                if HAS_TIMELIB:
                    # py3: yes, timelib.strtodatetime wants bytes, not str :/
                    return timelib.strtodatetime(
                        salt.utils.stringutils.to_bytes(date))
            except ValueError:
                pass

            # not parsed yet, obviously a timestamp?
            if date.isdigit():
                date = int(date)
            else:
                date = float(date)

        return datetime.datetime.fromtimestamp(date)
    except Exception:
        if HAS_TIMELIB:
            raise ValueError('Unable to parse {0}'.format(date))

        raise RuntimeError(
                'Unable to parse {0}. Consider installing timelib'.format(date))
610822
def date(value):
    
    if isinstance(value, str):
        value = to_date(value)
    return literal(value, type=dt.date)
983585
def date_from_string(string, format_string=None):
    """"""

    if isinstance(format_string, str):
        return datetime.datetime.strptime(string, format_string).date()

    elif format_string is None:
        format_string = [
            "%Y-%m-%d",
            "%m-%d-%Y",
            "%m/%d/%Y",
            "%d/%m/%Y",
        ]

    for format in format_string:
        try:
            return datetime.datetime.strptime(string, format).date()
        except ValueError:
            continue

    raise ValueError("Could not produce date from string: {}".format(string))
1084006
def _x_format(self):
        """"""

        def date_to_str(x):
            t = seconds_to_time(x)
            return self.x_value_formatter(t)

        return date_to_str
1259011
def _str_to_datetime(self, str_value):
        """"""
        try:
            ldt = [int(f) for f in str_value.split('-')]
            dt = datetime.datetime(*ldt)
        except (ValueError, TypeError):
            return None
        return dt
1149233
def _get_date_time_format(dt_string):
    '''
    
    '''
    valid_formats = [
        '%I:%M:%S %p',
        '%I:%M %p',
        '%H:%M:%S',
        '%H:%M',
        '%Y-%m-%d',
        '%m-%d-%y',
        '%m-%d-%Y',
        '%m/%d/%y',
        '%m/%d/%Y',
        '%Y/%m/%d'
    ]
    for dt_format in valid_formats:
        try:
            datetime.strptime(dt_string, dt_format)
            return dt_format
        except ValueError:
            continue
    return False
1160728
public static String formatDateAsYMD(Date date) {
        String retString = "";
        if (date != null) {
            retString = JinxUtils.ymdFormatter.format(date);
        }
        return retString;
    }
1047718
def _convert_date(self, date):
        """'"""
        return '/'.join([str(int(date.split('/')[0]) + 1911)] + date.split('/')[1:])