× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



That is similar to what I came up with:

String[] mdy = date.split("/");
java.text.SimpleDateFormat ymd = new
java.text.SimpleDateFormat("MM/dd/yyyy");
java.util.GregorianCalendar cal = new java.util.GregorianCalendar(
Integer.parseInt(mdy[2]), Integer.parseInt(mdy[0]),
Integer.parseInt(mdy[1]));
String dt = ymd.format(cal.getTime());

I did not want to hard-code the date format like that but at this point a
non-ideal solution is better than no solution.

Thanks,
Todd





"James Perkins"
<jrperkinsjr@gmai
l.com> To
Sent by: "Java Programming on and around the
java400-l-bounces iSeries / AS400"
@midrange.com <java400-l@xxxxxxxxxxxx>
cc

2008-11-05 18:07 Subject
Re: JDBC date insert

Please respond to
Java Programming
on and around the
iSeries / AS400
<java400-l@midran
ge.com>






I would think you should be able to use the SimpleDateFormat then to format
the date.

Probably not the most elegant, but...

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
import java.text.SimpleDateFormat;

public class TestStringDate {

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
int month = 0;
int day = 0;
int year = 0;
String stringDate = "11/4/2008";
Scanner scanner = new Scanner(stringDate);
scanner.useDelimiter("/");
int part = 0;
while (scanner.hasNext()) {
part++;
if (part > 3)
break;
if (scanner.hasNextInt()) {
switch (part) {
case 1:
month = scanner.nextInt() - 1;
break;
case 2:
day = scanner.nextInt();
break;
case 3:
year = scanner.nextInt();
break;
}
continue;
}
}

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
Calendar cal = new GregorianCalendar(year, month, day);
String s = sdf.format(cal.getTime());
System.out.println(s);
}

}


This will at least give you a string in the format you need.

James R. Perkins


On Wed, Nov 5, 2008 at 2:36 PM, <TAllen@xxxxxxxxxxxx> wrote:

I agree (again) that using strings is not ideal. Your guess is more or
less accurate. I'm using a set of classes for database access that does
not currently provide for SQL date objects.

Thanks,
Todd






This communication and any transmitted documents are intended to be confidential. If there is a problem with this transmission, please contact the sender. If the reader of this message is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.