• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL query retrieving date period from DB where one date has fixed month

 
Jonas Kazlauskas
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I am completely lost. I am coding a program where I can track my finances. In one of the components(JLabel) I want to see money spent from fixed day of the month to this day. For example: the day of the month I want to be fixed is every 10th of the month, since today is 29th i want to be able to calculate a sum of money spent from today to 10th of this month if day of this month is > then 10th and from today to the 10th of last month if todays day of the month is < then 10th. Any ideas how can I construct my SQL query?
 
Paul Clapham
Sheriff
Posts: 21550
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a query which looks like this:



Put that into a PreparedStatement. Then write some Java code which implements your requirements and produced a start and end date. Put those into the PreparedStatemen's parameters and execute it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic