Cannot delete users using whereClause with dates and lastLogin

Client SDK Android

Application ID 0557210D-0CD5-4724-FFDB-DB6B680CA200

Expected Behavior

Deleting objects from user table using where clause with dates, specifically lastLogin works.

String whereClause = "lastLogin before '" + sdf.format(calendarRef.getTime()) + "'";
int result = Backendless.Data.of("Users").remove(whereClause);

Actual Behavior

Running code pasted below gives exception. I don’t understand what am I doing wrong? Provided data format is supported.

BackendlessException{ code: ‘3027’, message: ‘Unknown error: Data truncation: Incorrect datetime value: ‘12/27/2020’ for column ‘lastLogin’ at row 1’, extendedData: ‘{}’, detail: ‘Unknown error: Data truncation: Incorrect datetime value: ‘12/27/2020’ for column ‘lastLogin’ at row 1’ }

Reproducible Test Case

final int maxNumOfMonths = 6;
final SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());

Calendar calendarRef = Calendar.getInstance();
calendarRef.add(Calendar.MONTH, -maxNumOfMonths);

String whereClause = "lastLogin before '" + sdf.format(calendarRef.getTime()) + "'";
int result = Backendless.Data.of("Users").remove(whereClause);

Hi Jakub,

As a workaround, you could use the datetime value as the number of milliseconds since the Unix epoch (the value returned by caledarRef.getTime().getTime() ) for some reason the lastLogin value doesn’t understand the stringified version of the date, however, a query with that format works fine for other columns such as created and updated

Regards,
Mark

unfortunately this solution does not work too, I get this error

BackendlessException{ code: ‘3027’, message: ‘Unknown error: Data truncation: Incorrect datetime value: ‘1609149517289’ for column ‘lastLogin’ at row 1’, extendedData: ‘{}’, detail: ‘Unknown error: Data truncation: Incorrect datetime value: ‘1609149517289’ for column ‘lastLogin’ at row 1’ }

Also in Backendless Console when I use search it does not work even though there are users who’s last login is before that date

Hi Jakub,

I opened an internal ticket to investigate the problem (BKNDLSS-25723).

Regards,
Mark

1 Like

Hi, @Jakub_Mirota

We’ve just updated cloud servers with a fix for the issue you described above. Could you kindly let us know whether fix works for you well?

Regards, Marina