Calculating the difference between dates

Hello!

i need to find files lower and bigger that one date i pass, i search in the man find, but i didn't find anything, the only that i find is the parameter -mtime, in this parameter i can pass a number of days, but i need to know the difference between dates, any built-in function for do this? or any parameter for pass to the find command?

Thanks!

hmm I am not shure if you could do that with some linux utility, maybe with scripting somehow, or ls -laR / and then use grep but this will have big overload

You can touch a temp file with the desired date, then use either

find path -newer tmp-file

or

find path ! -newer tmp-file

Note, with "! -newer", find will include files older OR EQUAL to the date.

I can't use this, because i need to pass a date, not a file.

It is worth using the search box at the head of the page for common questions like this. For example: -Difference between two dates...

I found a lot of posts of this, but i don't believe that not exists a built-in function for do this, really I need to copy the function to my code? or what i didnt' understand?

Why not ?

Pass the date to the function, in that function create a temp file and touch with the passed date.

Then you can use the suggested find command for the mentioned purposes.

I think what you are trying to say is that you need to calculate the difference between two dates and express that as a number of days, then pass the number to find's mtime option.

Is that it?

Yes, just it!

I will take a look at this later when I get home
In the meantime I have definitely seen posts here that give example code on how to subtract one date from another. Try searching for them. :slight_smile:

The program is not able to converting the Hexa decimal characters into Ascii characers in Unix.

The same program when i run in Windows, displaying �+�j�, but in unix dispalying different characters.

byte[] bytes = new byte[hex.length()/2];

[LEFT]for(int i=0;i<bytes.length;i++){
bytes = (byte)Integer.[i]parseInt(hex.substring(2i, 2i+2),16);
}
String multi = new String(bytes);
System.out.println(" multi value from unHex method "+multi);

Please guide me what i have to do in unix?[/LEFT]

I don't think that UNIX has any built in functionality for doing date math but there are plenty of sites on the web detailing various ways of attacking it. I use a function written in C myself but I cannot give it to you as it was written for the company I work for so is copyrighted.

However here is a link to a site with a C program you can compile that will do date subtraction: -

Date math in Linux shell script? :: Free Tech Support :: Ask Dave Taylor!

There are also posts on this site that do it pretty well in shell if you aren't concerned about leap years and so on.

Good luck

If you have GNU date then calculating the number of days from today is easy.

days_since() {
  echo $((($(date +%s)-$(date -d "$@" +%s))/3600/24))
}
me@tinybird:~$ days_since 20081019
365

The late. lamented Bob Stockler of Louiville , KY left behind his brilliant collection of scripts that do arithmetic with dates.

They're on my ftp site, ftp.jpr.com, in the /pub directory under the name datemath.tgz

Thanks jpr

Having a little trouble running datecalc.awk but I think it may be because of multiple #! lines at the begining, will experiment tomorrow.

Thanks for sharing

Thanks Scrutinizer, is just that i need!!!

And thanks to the other people too!