• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get a system date and store it in a variable?

 
Yuta Lolap
Ranch Hand
Posts: 86
Eclipse IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,
I am new to using the Date Class. Please can you guys help me out!

How to get a system date and store it in a variable of type date because i need to pass this into a query later on? Since i have to use it to fill a column called DateOfPurchase of type Date.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


now will contain exactly the system time, and allow you to do some cool things with it,
including converting to the older java.util.Date.

WP
 
Yuta Lolap
Ranch Hand
Posts: 86
Eclipse IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! I used the following code:



Now i have a column DOP right, so what if i wanna see all the items in month 'OCT'? How do i write the code for it?


Also, how do i do it in the above Calendar case with the object "now"?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using an SQL date rather than java.util.Date? Or better still, something from Yoda time or simliar?
 
Yuta Lolap
Ranch Hand
Posts: 86
Eclipse IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used your code and converted it to Util Date i guess this is how it is:



Is this conversion right? If not please do let me know. Can you help me with the month code? I need to see all the data for the month of OCT.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's better.

If you look up the Calendar API, you will see that it has a wealth of methods to help you out.

If all you want to show in your column are activities in October, this is very easy to do using Calendar.

WP
 
Yuta Lolap
Ranch Hand
Posts: 86
Eclipse IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it! Thanks!
 
Yuta Lolap
Ranch Hand
Posts: 86
Eclipse IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to say




Gives me an error says that i need to put it the following way

//have to give an sql cast to date1 thats wat it says
 
Yuta Lolap
Ranch Hand
Posts: 86
Eclipse IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wheni want util Date why is it saying i shud use the sql Date?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it saying you need an SQL Date? Are you inserting those values into a database? If so, you do need an SQL Date, but why didn’t you say so earlier?
 
Yuta Lolap
Ranch Hand
Posts: 86
Eclipse IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i am inserting into a db...
I am using the following code it works perfectly.




Also i have another issue...
I am using a Jtable... I have a db table purchases as follows:

SQL> desc purchases;
Name Null? Type
----------------------------------------- -------- ----------------------------
CUSTOMER_ID VARCHAR2(10)
ITEMID VARCHAR2(10)
ITEMNAME VARCHAR2(20)
ITEMPRICE NUMBER(10)
ITEMQUAN NUMBER(10)
DATEOFPURCHASE DATE

While viewing in a frame in a Jtable object being called from the Jtable(vector data, vector columnnames) constructor i want to view only columns ITEMID,ITEMNAME,ITEMPRICE,ITEMQUAN,DATEOFPURCHASE. But my code is not allowing me to do. In my code my vector retrieves all column names and displays all. I dont want that to happen. I just want the above columns. How do i do that?



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic