Forums Register Login

How to get the difference between 2 dates ?

+Pie Number of slices to send: Send
Hi folks,

I have 2 dates and need get the difference between these dates in days.
How can i do it ?

Regards,
+Pie Number of slices to send: Send
Hi,

I assume you have 2 java.util.Date, "just substract them".


Don't forget to check the sign of delta !

Arnaud
+Pie Number of slices to send: Send
i havent used java.util.date instead i have used ecternal plug-in Jcalender......since i have to so a complete Graphical app for the hotel....i need to use jCalender
+Pie Number of slices to send: Send
 

Ravi Hckd wrote:i havent used java.util.date instead i have used ecternal plug-in Jcalender......since i have to so a complete Graphical app for the hotel....i need to use jCalender



Not sure about Jcalendar plug in. But if it's similar to the Java class Calendar, then you can first convert the Calendar or Jcalendar to a Date then subtract.
+Pie Number of slices to send: Send
The functionality of the plug-in is different......you get the time /date in IS format.....but i'm unable to subtract the dates...all that i've done is or can be done is
convert it into string...can you tell me if is it possible to reconvert it into integer(the date stored as String) then subtract it.....
also should i upload the jCalender plug-in so that you can have a look??
+Pie Number of slices to send: Send
 

Ravi Hckd wrote:The functionality of the plug-in is different......you get the time /date in IS format.....but i'm unable to subtract the dates...all that i've done is or can be done is
convert it into string...can you tell me if is it possible to reconvert it into integer(the date stored as String) then subtract it.....
also should i upload the jCalender plug-in so that you can have a look??



You should check the API for JCalendar plug-in. Look for methods that converts a string to Date or long.

Having code examples can help us better understand your issue.
+Pie Number of slices to send: Send
I have pasted the code below and will also give a screen shot of the same

CODE:
Date dateFromDateChooser = jDateChooser1.getDate();
String dateString = String.format("%1$tY/%1$tm/%1$td", dateFromDateChooser);
dateFromDateChooser = jDateChooser2.getDate();
String dateString1 = String.format("%1$tY/%1$tm/%1$td", dateFromDateChooser);

The 2 different Date Choosers are used to choose the different dates....I'm unable to get the total number of Days from the above code.
1.jpg
THis is the image of working project
[Thumbnail for 1.jpg]
+Pie Number of slices to send: Send
Your code shows that you do in fact get the dates as Date objects. You're the one who is then formatting them to a string. Just use the Date objects, and you can use the approach that Arnaud suggested.

(Edit - that Arnaud suggested 8 years ago - you really should have opened a new thread for this).
+Pie Number of slices to send: Send
I'm new to this site....can you post that thread you mentioned for me?? Regarding the code...yes you do get the object but that's the dead end for it....
You cannot process it further( considering my knowledge:::: working on java first time------pretty different from .NET that;s why) or maybe there is another way....i don't know...
please can you give me the exact code for that...should i upload the entire application so that you get a better understanding....
waiting for your reply...do let me know
+Pie Number of slices to send: Send
 

Ravi Hckd wrote:yes you do get the object but that's the dead end for it....
You cannot process it further


Since you've got Date objects, you can do exactly what the message you replied to suggested:

Then divide by whatever is necessary to get it into whatever units you want.

+Pie Number of slices to send: Send
Thanks buddy.....the problem is solved.......
+Pie Number of slices to send: Send
hey there,

I am in a similar situation where am getting a DATE from oracle and counting the number of days till the current day.
Now, how to convert oracle DATE into java.util.DATE to find the difference in days ?

Thanks
Mark
+Pie Number of slices to send: Send
 

Mark Butcher wrote:
Now, how to convert oracle DATE into java.util.DATE to find the difference in days ?



There's no such thing as "convert oracle DATE into java.util.DATE to find the difference in days". At least, not without you making it.

There are two main parts to your question:

1) Convert oracle DATE into java.util.DATE. This is accomplished by calling ResultSet.getDate(...).

2) Find the difference between two dates. I believe that is answered in this thread.

So, what specifically are you having trouble with?
+Pie Number of slices to send: Send
@Jeff Verdegan :: If you have dates stored in Oracle you can write a simple function to get the number of days.....then all you need is to retrieve that integer value.......
Will post that function in sometime....also Oracle 11g Release 2 has excellent features regarding date manipulation.....hope this solves your problem
+Pie Number of slices to send: Send
 

Jeff Verdegan wrote:

Mark Butcher wrote:
Now, how to convert oracle DATE into java.util.DATE to find the difference in days ?



There's no such thing as "convert oracle DATE into java.util.DATE to find the difference in days". At least, not without you making it.

There are two main parts to your question:

1) Convert oracle DATE into java.util.DATE. This is accomplished by calling ResultSet.getDate(...).

2) Find the difference between two dates. I believe that is answered in this thread.

So, what specifically are you having trouble with?



@Jeff Verdegan :: If you have dates stored in Oracle you can write a simple function to get the number of days.....then all you need is to retrieve that integer value.......
Will post that function in sometime....also Oracle 11g Release 2 has excellent features regarding date manipulation.....hope this solves your problem
+Pie Number of slices to send: Send
 

Ravi Hckd wrote:@Jeff Verdegan ::....hope this solves your problem



I'm not the one having a problem. I was asking questions trying to get the OP to clarify what his problem is.

Good information about the Oracle date utilities though.
You've gotta fight it! Don't give in! Read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 6854 times.
Similar Threads
Dates..
difference between two dates
calculate difference in months
Get the Difference between 2 dates
Dates
Difference between 2 dates
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:45:46.