0

I need some help guys, i want to make a program that will be used to control the expiration date of some products, it will need to compare the system date with the date at DB ("oracle"), how can i compare these two and return the number of days left to the product expire.

I'll be glad if someone can help me with that. I have no idea from where to start.

LC1NS4N3
  • 74
  • 9
  • 2
    you start by learning each of the steps you described – user1231232141214124 Jun 09 '14 at 15:35
  • i've tried everything, but i don't know how to do it, i've already tried arrays, convert to milliseconds, compare date with date, but nothing works. – LC1NS4N3 Jun 09 '14 at 15:36
  • everything i know i've tried, that's because i'm here, to take a lead from someone about something i don't know and still trying to make it work. – LC1NS4N3 Jun 09 '14 at 15:39
  • what can i try to use to compare that, some class that i don't know ?, tell me and i search more about it, i don't want the entire code, just a lead to follow. – LC1NS4N3 Jun 09 '14 at 15:41
  • On the Oracle side you can just do `select trunc(sysdate) - my_date from my_product_table where my_product_id = ?`. – GriffeyDog Jun 09 '14 at 15:58

2 Answers2

2

Java has a built in date class which has many problematic issues, so it is not worth using. Instead, the Joda-Time api offers a reliable Java date and time API.

The API and some information about it can be found at http://www.joda.org/joda-time/.

A similar question has been asked already, and some answers and some example codes can be found at Number of days between two dates in Joda-Time.

For your case, instantiating a new time with a default constructor will give the system time: DateTime dt = new DateTime();

Once you get the expiration date from the database, just compare it to the system time as described in the question linked in my answer.

Community
  • 1
  • 1
jluckin
  • 662
  • 4
  • 6
1

If you are code in Java that will be hard 'cause you can easily decompile java and remove that part.

Maybe this:

public int DaysLeft(long DBDateTimeStamp) //Unix time
{
long curr = System.currentTimeMillis()/1000;
long left = DBDateTimeStamp - curr;
int left = left / (60*60*24);
return left;
}

or something like that.

KriszDev
  • 86
  • 1
  • 5