need help JDBC masters
Hi everybody;
i'm doing a web app to record TimeIn and TimeOut for the employees of the company...
now each branch of the company has a different timeIn (for ex. 10.00 or 8.00,,) and this is all stored in the DB..
what i'm doing is that i'm taking this time from the MS SQL DB as Timestamp, and getting the current time also as Timestamp...
now the current time is completely correct with the date (ex. 2007-07-22 08:45:00)
but the MS SQL DB Time is becoming like this when retriving it (1900-01-01 08:00:00)..
see...
the time is correct but the DATE !!!!!!
i want to know if the employee is late or not so when ever i'm using this:
currentTime.after(branchTime)
i'm getting true for sure...
now what i thought of doing is away of getting only the time from both Timestamp obejcts and compare it...
but again how to trim this object...
I don't know really.. help me find a solution...
Thanks in advance...
p.s if you need more info. pls inform me...
Q.Najjar (^_^);
# 1
Thanks for everyone who tried to think about it...
will i found a soultion for this matter. ..
and to get some exp. here it is:
1- I took the java.sql.Timestamp branchTime
and formed into string by calling toString();
2- using the substring(int beginIndex)
to cut the time and remove the wrong date:
ex. branchTime.toString() = 1900-01-01 08:00:00:0.0
so i cut the 08:00:00:0.0
and save it into another String..
3- now i took the current date from java.sql.Date
which gives correct date, so again i turn it into String and using substring()
i took the date like 2007-07-22
4- the last thing i did was to use the method timestamp.valueOf(String s)
which takes the string formed like this YYYY-MM-DD HH:MM:SS
and the string i passed to through the parameter of valueOf(String s)
was like this:
s = the date i got in step 3 + " " + the time i got from my DB
and here it is a new Timestamp with the right date and it just look like this 2007-07-22 08:00:00:0.0
I know it's complicated a bit, but at least i solved it...
hope that somebody would take benfit from this...
Thanks All
Q.Najjar (^_^);
# 4
> retriving it (1900-01-01 08:00:00)..
If you do not specify the date portion of the datetime value, then January 1, 1900 is supplied.
Looks like a lot of coding to fix this at the wrong point in the process. I think if I were you supervisor I would have to let you go for wasting all this time coding a work around rather then identifying and correcting the root cause of the problem. This incorrect / default date being stored in the database will continue to negatively effect future efforts. Why not correct it during the insert process and be done with it?
# 5
> I think if I were you
> supervisor I would have to let you go for wasting all
> this time coding a work around rather then
> identifying and correcting the root cause of the
> problem.
will thank God you're not my supervisor..
and then can you believe that i don't correct and use that right way, i was just affected by the long wheel i took, but later i thought about it and i knew that as you said in the future it will effect and later i will be responsible for fixing any errors.. so why the headaches..
thx for advice...(^_~);
# 6
Well, I wouldn't really have let you go, just made you think I might so you were scared of me all the time...
Seriously, that provocative comment was just for dramatic affect. I'm glad you figured out where the problem was and decided to correct it appropriately.
Best of luck to you.