Byron Bignell

Greenhorn
+ Follow
since Sep 29, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Byron Bignell

Hi,
Everyone here has been very supportive of my trashing about looking for solutions. This is THE BEST resource for Java/JSP, BAR NONE.
So...based on what I've learned here this is what I'm doing to compare dates from SQL and such...
This is what I did...
// Get the amount of time between the two dates
long msecs = date2.getTime() - date1.getTime();
// Create a GregorianCalendar and set its time zone to GMT
GregorianCalendar delta = new GregorianCalendar(
new SimpleTimeZone(5, ""));
// Set the calendar's time to the difference between the two
delta.setTime(new Date(Math.abs(msecs)));
// The "base" year is 1970, so subtract that number
out.println("Years: " +(delta.get(Calendar.YEAR) - 1970) + "<br>");
out.println("Months: " + delta.get(Calendar.MONTH) + "<br>");
// The "base" date is 1, so subtract that number
out.println("Days: " + (delta.get(Calendar.DATE) - 1) + "<br>");
out.println("Hours: " + delta.get(Calendar.HOUR) + "<br>");
out.println("Minutes: " + delta.get(Calendar.MINUTE) + "<br>");
out.println("Seconds: " + delta.get(Calendar.SECOND) + "<br>");
if(delta.get(Calendar.DATE) >= 3){
out.print("FLAGGED");
}
Question I have now is...can it be done more efficiently??
23 years ago
I DID IT ! I DID I! (With a WHOLE LOT of help from people here!!)
This is what I did...
// Get the amount of time between the two dates
long msecs = date2.getTime() - date1.getTime();
// Create a GregorianCalendar and set its time zone to GMT
GregorianCalendar delta = new GregorianCalendar(
new SimpleTimeZone(5, ""));
// Set the calendar's time to the difference between the two
delta.setTime(new Date(Math.abs(msecs)));
// The "base" year is 1970, so subtract that number
out.println("Years: " +(delta.get(Calendar.YEAR) - 1970) + "<br>");
out.println("Months: " + delta.get(Calendar.MONTH) + "<br>");
// The "base" date is 1, so subtract that number
out.println("Days: " + (delta.get(Calendar.DATE) - 1) + "<br>");
out.println("Hours: " + delta.get(Calendar.HOUR) + "<br>");
out.println("Minutes: " + delta.get(Calendar.MINUTE) + "<br>");
out.println("Seconds: " + delta.get(Calendar.SECOND) + "<br>");
if(delta.get(Calendar.DATE) >= 3){
out.print("FLAGGED");
}
Question I have now is...can it be done more efficiently??
Byron
23 years ago

Originally posted by Bal Sharma:
Hey Byron:
Have you try java.util.Calendar? I think it is pretty neat. I can use this class for whatever I wanna use. Simple example for today date is:
Calendar today = Calendar.getInstance();
int month = today .get(Calendar.MONTH);
int year = today .get(Calendar.YEAR);
int today = today .get(Calendar.DAY_OF_MONTH);
Once you get and set two different date. You can compare as you wish. Cann't you? I hope this will help you. BK


Hmm...I'll give it a go.
thanks
byron
23 years ago

Originally posted by Tim Holloway:
Are you using the java.sql.Date and java.util.Date classes?


hmmm...y'know, this nis the first I've heard of a sql.Date class...(guess that's why I'm here)
I was using the java.util.Date class and trying to get it to see the sql date as a date...no go...
this is what I'm doing...
rs.getDate("myDate")
and compare it to the current system date...
get the difference in days...
Byron
footnote:
Just looked at java.sql.Date...it's mostly deprecated...how useful can that be??

[This message has been edited by Byron Bignell (edited October 16, 2001).]
23 years ago
Please...please put me out of my misery!
WHY OH WHY IS WORKING WITH DATES SO HARD IN JAVA/JSP!
In ASP or ColdFusion comparing dates, getting the difference in years, months, weeks, days, hours, minutes, seconds is a breeze...
I have two dates in a database that I need to compare and get the difference in days...I can do it sitting on one hand.
I have to do this all the time in the apps I work on...there must be a better way to do this in JSP...
...please...please tell me how!
(begging for help...)
Byron
------------------

[This message has been edited by Byron Bignell (edited October 16, 2001).]
23 years ago
Got it! Got it!
(sound of palm smacking forhead!)
//first, don't just get the string as a string, get it as a date...
Date mydate = qryItems.getDate("TargetDate");
//after that is all gets easier...
SimpleDateFormat sdf = new SimpleDateFormat ("dd-MMM-yyyy");
String thedate = sdf.format(mydate);
out.println(thedate);
Major sigh of relief here...tome for that beer and some chips!
Byron
23 years ago
HI.
I edited the code bit...
I'm having this problem formatting the date field of a SQL record set to a nice looking date in the JSP template...
It works just fine if I use an actual date...but if I try to parse the datetime from an ODBC/JDBC recordset I get an unparable string...or something equally as nasty.
In the end I just need to be able to make this:
2002-01-10 00:00:00.0
into
Jan 10 2001
in a JSP template.
Byron
23 years ago
HI.
Ok, real green question, and this even after I've looked through the forums for how to format a date returned from SQL.
What I need is clarification really.
Is this right? Or is there a better way to do this?

Many thanks...
BTW...
I'm about 1/4 of the way through my first JSP/Bean project...converting a ColdFusion app...it's been great and I'm learning a huge amount.
Byron
[This message has been edited by Byron Bignell (edited October 05, 2001).]
23 years ago

Originally posted by Jim Yingst:
OK, now that we can read it, it looks like this is a simple case of using " == foo" where ".equals(foo)" is more appropriate.


"sound of palm smacking forehead..."
Wow. it works! (learned something new today)

23 years ago
greenhorn greetings:
What am I doing wrong here? It looks like it should work, but everything always fails in the second loop.
Help me please!
Byron

[This message has been edited by Byron Bignell (edited September 30, 2001).]
23 years ago
greenhorn greetings:
What am I doing wrong here? It looks like it should work, but everything always fails in the second loop.
Help me please!
Byron

[This message has been edited by Byron Bignell (edited September 30, 2001).]

[This message has been edited by Jim Yingst (edited September 30, 2001).]
23 years ago
Hi,
I've worked this out. It behaves well. But part of me thinks that there must be a better way to do this...
int counter1 = 1;
String clientlist = "";
if (counter1 < qryClient.getRowCount()){
clientlist = clientlist + qryClient.get("ClientID") + ",";
} else {
clientlist = clientlist + qryClient.get("ClientID");
}
counter1 = counter1 + 1;


[This message has been edited by Byron Bignell (edited September 29, 2001).]
23 years ago
Greetings from a greenhorn.
After putzing around with this for a while I've come here to seek advice.
What is an effective way to create a comma delimited list suitable for use in a SQL query?
I need to run one query, take all the UUID's from it, create a list and pass it as a variable to the next query for use in a where clause:
like this:
first query:
select taxid from clients
create the comma delimited list...
then use it in the 'where in' clause of the next sql query.
thanks loads.
Byron
select * from taxes where taxid in ('<%=list%>')
23 years ago