i try to get this Query running but it does not work like i expected.
In the table is a Date Field Formatted as Text (can't change it) and i need to filter this Column.
Dates looks like
11/03/2022 (d/m/Y)
My Query looks like
session.query(DBGEUK)\
.filter(DBGEUK.VALIDATOR == '58')\
.filter(func.CDate(DBGEUK.DATE) <= datetime.now())\
.all()
There is a total of 24 entry's. When i run the Query above and print out the DBGEUK.DATE + datetime.now, this 9 entry's are my result.
27/03/2022 2022-03-28 19:06:49.465406
27/03/2022 2022-03-28 19:06:49.480988
27/03/2022 2022-03-28 19:06:49.480988
27/03/2022 2022-03-28 19:06:49.480988
28/03/2022 2022-03-28 19:06:49.480988
28/03/2022 2022-03-28 19:06:49.480988
28/03/2022 2022-03-28 19:06:49.480988
28/03/2022 2022-03-28 19:06:49.481612
28/03/2022 2022-03-28 19:06:49.481727
If i change the Query to greater then >= i got the other 15 entry's
04/03/2022 2022-03-28 19:09:09.030659
04/03/2022 2022-03-28 19:09:09.031659
04/03/2022 2022-03-28 19:09:09.031659
04/03/2022 2022-03-28 19:09:09.031659
04/03/2022 2022-03-28 19:09:09.031659
05/03/2022 2022-03-28 19:09:09.031659
05/03/2022 2022-03-28 19:09:09.031659
05/03/2022 2022-03-28 19:09:09.031659
05/03/2022 2022-03-28 19:09:09.032657
11/03/2022 2022-03-28 19:09:09.032657
12/03/2022 2022-03-28 19:09:09.032657
11/03/2022 2022-03-28 19:09:09.032657
11/03/2022 2022-03-28 19:09:09.032657
09/03/2022 2022-03-28 19:09:09.033654
09/03/2022 2022-03-28 19:09:09.033654
Thanks for your help in advanced.
The
CDate()function tries to interpret date string literals according to the date formatting settings in the Windows control panel. With a "short date" setting ofMM/dd/yyyy,CDate("03/07/2022")evaluates to March 7, 2022. With a "short date" setting ofdd/MM/yyyy,CDate("03/07/2022")evaluates to July 3, 2022.However, if the date string represents an invalid date then
CDate()will be "helpful" and return a valid date using the other format. In both cases above,CDate("14/03/2022")will evaluate to March 14, 2022.Unfortunately, this means that
Therefore in this case we need to avoid using
CDate()and parse the date string ourselves: