-1

when I output these two SQL operations, the columns for the two months (01 = January) and (02 = February) are summed together instead of individually. So they show the same output. But why? If if want to output (02 February) it should not show the sum of January but it does. Where is my problem in my code?

"SELECT SUM(" + dataBaseHelper.GET_SUM + ") FROM " + dataBaseHelper.TABLE_NAME + " WHERE " + dataBaseHelper.DATE + " BETWEEN '01/01/2022' AND " + "'07/01/2022'"

and

"SELECT SUM(" + dataBaseHelper.GET_SUM + ") FROM " + dataBaseHelper.TABLE_NAME + " WHERE " + dataBaseHelper.DATE + " BETWEEN '01/02/2022' AND " + "'07/02/2022'"
yesmen
  • 123
  • 7

1 Answers1

3

The standard syntax for date in MySQL is yyyy-mm-dd. I think you could replace the dates in your where between statement using this consideration. Otherwise read string to date cast specifications.

asd-tm
  • 3,381
  • 2
  • 24
  • 41
  • Do I also have to adjust the format of my date in the database, or only if I want to call up the data from the database – yesmen Jan 04 '22 at 22:05
  • By default you will not need to change any settings of MySQL server when fetching records with where statement like `where myDate = '2021-12-25'` – asd-tm Jan 04 '22 at 22:07