| Author |
Insert the current date
|
Rajkumar balakrishnan
Ranch Hand
Joined: May 29, 2008
Posts: 445
|
|
Hi friends,
I need to insert the current date in the MySQL table and when i try to do so a compilation error occurs..
: Edited :
|
Never try to be a hard-worker. Be a smart-worker.
My Blog
|
 |
Rene Larsen
Ranch Hand
Joined: Oct 12, 2001
Posts: 1179
|
|
|
You need to insert a 'java.sql.Date' into 'ps.setDate(1, ...)'
|
Regards, Rene Larsen
Dropbox Invite
|
 |
Rajkumar balakrishnan
Ranch Hand
Joined: May 29, 2008
Posts: 445
|
|
Originally posted by Rene Larsen: You need to insert a ' java.sql.Date' into 'ps.setDate(1, ...)'
I want to insert the current date into table, but i don't know how to accomplish that.. Please post me some code here..I am in :roll: Please help me..........
|
 |
Shailesh Chandra
Ranch Hand
Joined: Aug 13, 2004
Posts: 1076
|
|
Originally posted by Rajkumar balakrishnan: I want to insert the current date into table, but i don't know how to accomplish that.. Please post me some code here..I am in Please help me..........
Thanks, Shailesh
|
Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
|
 |
Rajkumar balakrishnan
Ranch Hand
Joined: May 29, 2008
Posts: 445
|
|
Originally posted by Shailesh Chandra: Thanks, Shailesh
Thanks for that... And now a silly question is this one stores the time in milliseconds where i need it to be stored in yyyy-MM-dd format so that i can able to view it in reports.... Please help me regards this
|
 |
Rene Larsen
Ranch Hand
Joined: Oct 12, 2001
Posts: 1179
|
|
|
|
 |
Rene Larsen
Ranch Hand
Joined: Oct 12, 2001
Posts: 1179
|
|
Originally posted by Rajkumar balakrishnan: Thanks for that... And now a silly question is this one stores the time in milliseconds where i need it to be stored in yyyy-MM-dd format so that i can able to view it in reports.... Please help me regards this
If you need to show the date in a special format, you need to use SimpleDateFormat to format the date/timestamp returned fra the database.
|
 |
Rajkumar balakrishnan
Ranch Hand
Joined: May 29, 2008
Posts: 445
|
|
Originally posted by Rene Larsen: If you need to show the date in a special format, you need to use SimpleDateFormat to format the date/timestamp returned fra the database.
Is there anyway to store the current date in the specified format...???
|
 |
Rene Larsen
Ranch Hand
Joined: Oct 12, 2001
Posts: 1179
|
|
Originally posted by Rajkumar balakrishnan: Is there anyway to store the current date in the specified format...???
Yes as a String (varchar).
|
 |
Rajkumar balakrishnan
Ranch Hand
Joined: May 29, 2008
Posts: 445
|
|
|
: Edited :
|
 |
Rene Larsen
Ranch Hand
Joined: Oct 12, 2001
Posts: 1179
|
|
To be able to store the date as a String (varchar) in the database, you need to verify that the data type for the 'date' field is a varchar - or you have to change it from date/timestamp to varchar. Here is how you put a Date as a String into the database:
|
 |
Rajkumar balakrishnan
Ranch Hand
Joined: May 29, 2008
Posts: 445
|
|
Originally posted by Rene Larsen: To be able to store the date as a String (varchar) in the database, you need to verify that the data type for the 'date' field is a varchar - or you have to change it from date/timestamp to varchar. Here is how you put a Date as a String into the database:
I dont want to change the field from date to varchar or something else.. So please help me inserting the current date with the required formatting....
|
 |
Shailesh Chandra
Ranch Hand
Joined: Aug 13, 2004
Posts: 1076
|
|
Originally posted by Rajkumar balakrishnan: I don't want to change the field from date to varchar or something else..
You should not! a date field should be of date type only in database
So please help me inserting the current date with the required formatting....
Why are you so specific about format, A date is stored in database as Date object not with its format. A format is only representation of date as string. I suggest let the date be stored as Date and if you want to display same in a specific format is as Rene has suggested above. That would be an ideal approach. Thanks, Shailesh
|
 |
Rajkumar balakrishnan
Ranch Hand
Joined: May 29, 2008
Posts: 445
|
|
Originally posted by Shailesh Chandra: Why are you so specific about format, A date is stored in database as Date object not with its format. A format is only representation of date as string. I suggest let the date be stored as Date and if you want to display same in a specific format is as Rene has suggested above. That would be an ideal approach. Thanks, Shailesh
I have done it by the instructions given by the Rene..... Thanks ranchers for helping me... Real life-savers.....
|
 |
 |
|
|
subject: Insert the current date
|
|
|