#1 2009-01-08 08:54

teppi_04
Member
Registered: 2009-01-08
Posts: 2

How to calculate time and rename file.

I want to rename pic file of my son. New filename indicates old day(month/year) of  him at taken date.

Ex: His birthday: 12.02.2008
        Take date: 11.05.2008
    Newfilename: 02month19day.jpg

Help me please!

Offline

#2 2009-01-08 19:39

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: How to calculate time and rename file.

Hi teppi_04, welcome and congratulatory to become an daddy big_smile

teppi_04 wrote:

I want to rename pic file of my son.
New filename indicates old day(month/year) of  him at taken date.

Ex: His birthday: 12.02.2008
        Take date: 11.05.2008
    Newfilename: 02month19day.jpg

Where comes the '19' from ? big_smile

Please provide 8 original file names and the names you want to get as pairs, so we can help you. For example:

Original name - New name
xyz.jpg          - 0212.jpg


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2009-01-09 06:10

teppi_04
Member
Registered: 2009-01-08
Posts: 2

Re: How to calculate time and rename file.

New filename indicates old day(month/year) of  him at taken date.

His birthday: 2008-02-12


Original name                -        New name
2008-02-25.jpg               -      0Year-0Month-13day.jpg
2008-03-15.JPG              -      0Year-1Month-3day.jpg
2008-03-15.JPG              -      0Year-1Month-3day.jpg
2008-03-16.JPG              -      0Year-1Month-4day.jpg
2008-05-13.JPG              -      0Year-3Month-1day.jpg
2008-05-25.JPG              -      0Year-3Month-13day.jpg
2008-06-05.jpg               -      0Year-3Month-24day.jpg
2008-09-06.JPG              -      0Year-6Month-25day.jpg



Thanks so much

Offline

#4 2009-01-09 13:06

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: How to calculate time and rename file.

Ahh, now i understand big_smile


Original name                -  His birthday   -   New name
2008-02-25.jpg     minus    2008-02-12 =    0Year-0Month-13day.jpg

That can be done with an script.
But that's not that easy because you have to take care of all those rules ( day of months, leap year,...)

ReNamer can use Pascal Script to rename files and can use external tool too.  f.ex.: http://www.den4b.com/forum/viewtopic.php?id=536
But you can also use ReNamer to export the file name -> use any script language you like -> and re-import the new names.
Now all you need is someone who can provide you such an script... or do you code on your own?


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#5 2009-01-10 10:31

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: How to calculate time and rename file.

Ok, this is the best I could come up with...

{ Date Difference Script v1 by Andrew }

var dtarr: TStringsArray;
var bday,filedt: TDateTime;
var filey,filem,filed,diffy,diffm,diffd: Word;

begin
  bday := EncodeDate(2008, 2, 12);
  dtarr := WideSplitString(WideExtractBaseName(FileName), '-');
  filey := StrToInt(dtarr[0]);
  filem := StrToInt(dtarr[1]);
  filed := StrToInt(dtarr[2]);
  filedt := EncodeDate(filey, filem, filed);
  if (bday > filedt) then Exit;
  DecodeDate(filedt-bday+1, diffy, diffm, diffd);
  diffy := diffy - 1900;
  diffm := diffm - 1;
  FileName := IntToStr(diffy)+'Year-'+IntToStr(diffm)+'Month-'+IntToStr(diffd)+'Day'+WideExtractFileExt(FileName);
end.

Unfortunately, the output doesn't completely match what teppi_04 specified above. sad

2008-02-25.jpg        0Year-0Month-13Day.jpg
2008-03-15.jpg        0Year-1Month-1Day.jpg
2008-03-16.jpg        0Year-1Month-2Day.jpg
2008-05-13.jpg        0Year-3Month-1Day.jpg
2008-05-25.jpg        0Year-3Month-13Day.jpg
2008-06-05.jpg        0Year-3Month-24Day.jpg
2008-09-06.jpg        0Year-6Month-26Day.jpg

I think this is because sutracting two TDateTime variables in PascalScript doesn't take into account the number of days in the intervening months, leap years (Feb.) etc. If that had been implemented properly like in other languages, things would have been so simple... smile Maybe Denis can help?

So teppi_04, the thing is, either you find this enough for your needs, or else someone has to sit and write a whole new datediff() function, with days per month arrays, code for finding leap years etc. Not impossible certainly, but will take some time. It might even be far simpler to write a renaming program only for this specific case in some other language that can properly carry out date arithmetic!

Edit: Yes! Woohoo! This is nice logic if I do say so myself! tongue cool

{ Date Difference Script v2 by Andrew }

var dtarr: TStringsArray;
var bday,filedt: TDateTime;
var filey,filem,filed,diffy,diffm,diffd: Word;

begin
  bday := EncodeDate(2008, 2, 12);
  dtarr := WideSplitString(WideExtractBaseName(FileName), '-');
  filey := StrToInt(dtarr[0]);
  filem := StrToInt(dtarr[1]);
  filed := StrToInt(dtarr[2]);
  filedt := EncodeDate(filey, filem, filed);
  if (bday > filedt) then Exit;
  diffy := 0; diffm := 0; diffd := 0;
  while (true) do
  begin
    if (IncYear(bday, 1) <= filedt) then
    begin
      bday := IncYear(bday, 1);
      diffy := diffy + 1;
    end
    else if (IncMonth(bday, 1) <= filedt) then
    begin
      bday := IncMonth(bday, 1);
      diffm := diffm + 1;
    end
    else if (IncDay(bday, 1) <= filedt) then
    begin
      bday := IncDay(bday, 1);
      diffd := diffd + 1;
    end
    else
      break;
  end;
  FileName := IntToStr(diffy)+'Year-'+IntToStr(diffm)+'Month-'+IntToStr(diffd)+'Day'+WideExtractFileExt(FileName);
end.

P.S. For both scripts, the filenames should always be in the format - yyyy-mm-dd.jpg

Last edited by Andrew (2009-01-10 12:36)

Offline

Board footer

Powered by FluxBB