This is decided NOT a language-neutral question. Java and Javasript and every SQL implementation I've ever used, for example, have date/time compare functions that work just fine. If the language or platform that you are using does not, you'd have to tell us what they are for anyone to be able to tell you what the correct function call to use is or how to work around some idiosyncracy. Yes, many languages have a date/time datatype, but that doesn't make the question language neutral. Most languages have a way to output text to the screen, but that doesn't make it legitimate to ask, "How do I write a text string to the screen in a language neutral way?" There is no answer to such a question.
I have no idea what you mean by "it only compares by last comparison". Again, you are apparently referring to the behavior of some particular comparison function in some particular language. You have to be more specific to get a meaningful answer.
Edit in reply to your comment: Different languages have different ways of storing dates. In Java, to see if one date/time is after another you write "date1.after(date2)" or "date1.compareTo(date2)>0". In Postgres SQL you write "date1>date2" or "date1::timestamp>date2::timestamp" depending on type definitions. In C there are a variety of "right" ways, including "difftime(date1, date2)". Etc etc.
Aaron's answer above is logically correct but irrelevant to how you actually compare dates in any language I use. If you had dates stored as a set of integers for each of these components (year, month, day, etc.), sure that would work. But I don't know of any language that stores dates that way.
If you have some reason for having your own format for storing dates, and breaking them out into components like this is useful for your application, then I suppose Aaron's technique is correct. But it is very unlikely that this is a useful format. Internally, Java stores date/time as number of milliseconds since midnight, Jan 1, 1970. C uses number of seconds. I'm sure other languages use other schemes.
You can, of course, write language-neutral pseudocode to compare two dates, just like you could write language-neutral pseudocode to describe writing to a screen. If your goal is to abstract the technical details of a language away while you work on a bigger problem, great. But if your goal is to actually compare two dates and find which is later or how many days are between them, then the answer lies in the technical details of how the particular language that you are using stores and manipulates dates.