Results 1 to 10 of 10
Thread: Date operations
- 07-20-2010, 09:44 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 7
- Rep Power
- 0
Date operations
Hi
I need to convert a string to Date to build a query. Following are the values which i am recieving from front end
String date = 06/21/2010
while running the query on database table the date should be in following format
2010-06-21 18:18:02.732
Here is what i tried
Date = Date.replace('/','-');
String pattern = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
String dateStartRange = sdf.format(sdf.parse(Date))
+ " 00:00:00.0";
String dateEndRange = sdf.format(sdf.parse(Date))
+ " 23:59:59.0";
Function call sdf.format(sdf.parse(Date)) is not returning correct values
please advise
- 07-20-2010, 09:48 PM #2
Please show the actual code and what was returned.not returning correct values
- 07-20-2010, 09:51 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 7
- Rep Power
- 0
The value of dateStartRange in statement
String dateStartRange = sdf.format(sdf.parse(Date))
+ " 00:00:00.0"; is returned as 0013-03-02 00:00:00.0
- 07-20-2010, 09:57 PM #4
Please show the actual code and what was returned.
Sorry, I meant the all of the code showing the input, formatting and output.
You've left off the definition and values of sdf and Date.
Something that can be compiled and executed to show the problem.
- 07-20-2010, 10:09 PM #5
Member
- Join Date
- Jun 2010
- Posts
- 7
- Rep Power
- 0
Hi Norm
import java.text.SimpleDateFormat;
import java.util.Date;
String Date = "06/21/2010";
Date = Date.replace('/','-');
String pattern = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
String dateStartRange = sdf.format(sdf.parse(Date))
+ " 00:00:00.0";
String dateEndRange = sdf.format(sdf.parse(Date))
+ " 23:59:59.0";
****************************
I am expecting the value of dateStartRange = 2010-06-21 00:00:00.0 and value of dateEndRange = 2010-06-21 23:59:59.0
But these are coming out to be
dateStartRange= "0013-03-02 00:00:00.0"
dateEndRange= "0013-03-02 23:59:59.0"
- 07-20-2010, 10:26 PM #6
You need separate patterns for the input and for the output.
- 07-20-2010, 10:31 PM #7
Member
- Join Date
- Jun 2010
- Posts
- 7
- Rep Power
- 0
hmm i am not sure i understand this, how can i set separate patterns for inpit and output
- 07-20-2010, 10:33 PM #8
One to parse the input and one to format the output
- 07-20-2010, 10:59 PM #9
Member
- Join Date
- Jun 2010
- Posts
- 7
- Rep Power
- 0
Thnx that solved my problem
- 07-21-2010, 09:13 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Bitwise operations with long
By NewJavaBean in forum New To JavaReplies: 2Last Post: 04-07-2009, 07:37 PM -
Compare date input to database with current date
By hungleon88 in forum Advanced JavaReplies: 2Last Post: 11-25-2008, 08:10 AM -
Illegal Arithmetic Operations?
By Cruor in forum New To JavaReplies: 13Last Post: 09-19-2008, 04:46 PM -
Creating a Gregorian Calendar using a Date object gives date - 1
By prachi_goliwadekar in forum New To JavaReplies: 1Last Post: 05-08-2008, 08:32 PM -
String operations..
By sireesha in forum New To JavaReplies: 4Last Post: 12-14-2007, 02:04 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks