• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date problem

 
sandeep balyan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
c in my case IAm inserting date in oracle table..
i have to insert in MonthYYYY format and this is one of my key..
If i insert in this format i get the date as 1st of month and year
like this 1 july 2002 and i want only july 2002
and suggestion for inserting in oracle
regds
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look in the java.text package for the SimpleDateFormat class. It gives you a great deal of control over how a date is formatted.
Bill
 
sandeep balyan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for answer
I am using java.text b4 only but the problem is this when i insert the format monthyyyy in oracle
it is inserted in format of ddmonth yyyy
and as it is a key for me that to insert only once in a month .
exactly i want to insert date in format monthyyyy
so that i can resist to insert again in same month
thanks
regds
 
Piyush Daiya
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Well, what you can try is , do modifications in ur SQL statements where you actually insert the record.
Something like,

Insert into Table(recDate) values ( To_Date(jspDate,'MM/RRRR'));
where jspDate is Date from ur jsp page.
To_Date() is oracle function.
This will work for oracle only.
Hope this helps you out.

Regards,
Piyush
 
sandeep balyan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
C Iam inserting date in this way only..
insert into table(tdate)values
(to_date('"+S3+"','Monthyyyy'));
Here S3 is a date variable java.sql
It is inserting date but the format is the same
default format of oracle dd-mon-yy
and it inserts with the 1st date of month ..
c if i insert this month it will insert 1-july-2002
and i want only july2002
any suggestion
thanks
 
Piyush Daiya
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
try making the column in the database where u storing the info as varchar2 instead of date and then try.I think it will work.
Piyush
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to step back from the immediate problem for a moment and ask yourself what exactly is wrong with it using the first day of the month?
If your system is only concerned with the month and the year, surely it doesn't matter if the database decides to store a day with it. Have you written the code which uses or displays this stored month/year field yet? Does that code care whether there is a day stored with it, or just use/display the month and year?
I think the database is just being sensible. You have asked to store a month and year in a date field, so it has defaulted the day to the first to make it a valid date.
Put another way. If I hand you a one-page-per-day diary and ask you to point to "July 2002", which page do you point to?
 
Syam Veerakumar
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piyush Daiya and Frank Carver are rite, You can't store just month and year in Oracle Date column I guess,so make it a varchar2 column in database or retrive full date from the database and parse it in frontend as per u'r application.
 
Xuening Ma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guy, try to use rs.getString() to read the DateTime out first, then use SimpleDateFormat to convert the string to your Date format, I tested it, works very well.
 
sandeep balyan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is okee..man
U cant use varchar2() in u r application instead of Date as u cant operate on oracle date Queries..
I got solution for that man ..
I am inserting right values and it is showing 1st day of month due to the oracle server default format .
so what ever in what ever format i insert date
it will show in its default format..
so nothing to change only change default date format of oracle....
thx guys
regds
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!