• Post Reply Bookmark Topic Watch Topic
  • New Topic

A question on java.util.Date  RSS feed

 
fedai gandjaliyev
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I have a method returning String value containing current day of month.

public String currDay(){
simpleDF = new SimpleDateFormat("dd");
currDate = new Date(System.currentTimeMillis());
String currDay = simpleDF.format(currDate);
return currDay;
}

How can I make it return a Date value containing days only?
In a word I need a method returning Date value containing days only?
Waiting for reply...........
Thank you!
Fedai!
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you give an example of what you want?
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right now it's returning "02". And you want it to return a Date object containing only 2? That doesn't make sense. However, maybe the requirement that made you ask that makes sense. What is it?
 
fedai gandjaliyev
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is that I have to query certain fields from a MySQL table.
This table has a field of sql DATE type.
I have to retrieve those fields for which the day part of that date in the field coincides
with the current day of the month.
Like this.
If this is the mehtod I need
public Date getCurrDay(){
.........................................
}
then this is what I do
Date currDay = getCurrDay();
getInfoStat = conn.prepareStatement("SELECT Name, Surname, PersonID FROM persn WHERE BirthDate LIKE ? ");
getInfoStat.setDate(1, currDate);
..............................................................
This is why I need such a method!
Waiting for reply..............
Thank you!
 
fedai gandjaliyev
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The above makes me create a method like that
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First thing to do is to find the SQL function that your database provides to get the "day-of-month" part of a date column. Let's suppose it's DAYOFMONTH. Then your code should look like this:
 
fedai gandjaliyev
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved it!
Thank you!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!