One of the parameterized SQL of the cohort method does this
```sql
AND cohor…t_start_date >= CAST('@study_start_date' AS DATE)
```
the bigquery translation is attempting to do this
```sql
cohort_start_date >= cast('20050101' as date)
```
However, according to BQ docs [here](https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#casting)
> Casting from a date type to a string is independent of time zone and is of the form YYYY-MM-DD.
I believe the issue may be solved modifying the csv file here `inst/csv/replacementPatterns.csv` with:
```sql
IF (REGEXP_CONTAINS(CAST(@a AS STRING), r'[0-9]{8}.*'),
PARSE_DATE('%Y%m%d', REGEXP_EXTRACT(CAST(@a AS STRING),r'[0-9]{8}')),
IF (REGEXP_CONTAINS(CAST(@a AS STRING), r'[0-9]{4}-[0-9]{2}-[0-9]{2}.*'),
PARSE_DATE('%Y-%m-%d',
REGEXP_EXTRACT(CAST(@a AS STRING),r'[0-9]{4}-[0-9]{2}-[0-9]{2}')),
PARSE_DATE('%Y/%m/%d',
REGEXP_EXTRACT(CAST(@a AS STRING),r'[0-9]{4}.{1}[0-9]{2}.{1}[0-9]{2}'))))
```
I did the following unit test with the following DrugExposureLongTerm
```R
sql = "SELECT CAST('20100112' AS DATE);SELECT CAST('2010/01/12' AS DATE);SELECT CAST('2010-01-12' AS DATE)"
print(translate(sql=sql, 'bigquery'))
```
```SQL
SELECT
IF
(REGEXP_CONTAINS('20100112', r'[0-9]{8}'),
PARSE_DATE('%Y%m%d',
'20100112' ),
IF
(REGEXP_CONTAINS('20100112', r'[0-9]{4}-[0-9]{2}-[0-9]{2}'),
PARSE_DATE('%Y-%m-%d',
'20100112' ),
PARSE_DATE('%Y/%m/%d',
'20100112' )));
SELECT
IF
(REGEXP_CONTAINS('2010/01/12', r'[0-9]{8}'),
PARSE_DATE('%Y%m%d',
'2010/01/12' ),
IF
(REGEXP_CONTAINS('2010/01/12', r'[0-9]{4}-[0-9]{2}-[0-9]{2}'),
PARSE_DATE('%Y-%m-%d',
'2010/01/12' ),
PARSE_DATE('%Y/%m/%d',
'2010/01/12' )));
SELECT
IF
(REGEXP_CONTAINS('2010-01-12', r'[0-9]{8}'),
PARSE_DATE('%Y%m%d',
'2010-01-12' ),
IF
(REGEXP_CONTAINS('2010-01-12', r'[0-9]{4}-[0-9]{2}-[0-9]{2}'),
PARSE_DATE('%Y-%m-%d',
'2010-01-12' ),
PARSE_DATE('%Y/%m/%d',
'2010-01-12' )))
```
@pavgra