• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date problem

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a html form from where I get date as Aug 8 2003 when I do
request.getPArameter("empdate")

When use this value in preparedsql ... my sql does not work.

I am using DB2 and When I try 'mm/dd/yy' in command center it works fine.

the emp date is stored in db as aug 6, 2003 ..but somehow it does not work when i use the same format to retrieve info. Why? and how to solve this problem
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More about JBDC than JSP, so moving appropriately.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34870
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shan,
Since you are using prepared statements, you don't need to worry about the date format for insertions. Try using setDate(). For example:

The driver will handle the format for you.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for retrieving use,

rs.getDate(int i);

then parse it into any format you wish, using SimpleDateFormat class or Calendar.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my select st is

select eno, ename where empdate between ? and ?

from the html form I get date as aug 8 2004 to sep 8 2004

when I use mm/dd/yyyy format it works fine but not with above format.

How do I convert my input to mm/dd/yyyy format?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shan,

Jeanne said something above. Else please paste some code snippet then we will know what are having really. and please paste the exception stack as well if there is any.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://javascript.internet.com/forms/val-date.html

I use the above code to validate my dates in my html page. the dates returned by them are like sep 5 2004

public emp get_emp()

select * from emp where emp_date between ? and ?

String dt1 = request.getparameter(date1)
String dt2 = request.getparameter(date2)

ps.setString(1,dt1);
ps.setString(2,dt2);
ps.executequery();

}

I get this error when I execute the sel st with date format as sep 8 2003
sep 9 2004 in command center

The syntax of string representation of a datetime value is incorrect

But when I use mm/dd/yyyy forrmat in command centre it works fine.


try{
Log.writeMessage(Log.LOG_LEVEL_DEBUG, "1");
String strTmp = "sep 21 2004";
Log.writeMessage(Log.LOG_LEVEL_DEBUG, "2");
java.util.Date dtTmp = new SimpleDateFormat("mon dd yyyy").parse(strTmp);
Log.writeMessage(Log.LOG_LEVEL_DEBUG, "3");
String strOutDt = new SimpleDateFormat("mm/dd/yyyy").format(dtTmp);
Log.writeMessage(Log.LOG_LEVEL_DEBUG, "strOutDt = " + strOutDt);
}catch(Exception ex){}

I just wrote the above program and I see the code is stuck at "bold " line
I get 1 and 2 as print but not three? Why?
Error I get is unparsebale date

[ October 07, 2004: Message edited by: shan javan ]
[ October 07, 2004: Message edited by: shan javan ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34870
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shan,
The format should use "M" for the month rather than "mon".
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lets take "January" as an example.

MM = 01
MMM = Jan
MMMMM = January

Single "M" is nothing.
"mon" is nothing.

for more, plz. read the docs.
[ October 07, 2004: Message edited by: adeel ansari ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic