#1 2009-09-26 10:16

wascko
Member
Registered: 2009-09-26
Posts: 2

Changing dates by adding substracting a time-span

I  have a bunch of pictures in this format YYYY_MM_DD...  but with a wrong date (the camera date was not initialized to the correct date)
eg 2008-10-31_19-24-27.JPG

i am looking for a pascal script that can ad or substract a timespan to correct the date.

Pretty stupid :
I found a script somewhere some time ago and i forgot to safe it : S
roll

anybody ?

Offline

#2 2009-10-04 14:48

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,370

Re: Changing dates by adding substracting a time-span

This script is included in the ReNamer. It is called "Hours span".

Here is the code for the reference:

// This script reads dates from filenames in format: yyyy-mm-dd hh-nn-ss.JPG
// then adds/subtracts N hours from the date and prints the new date in the
// format defined by DateOutputFormat variable. HoursSpan variable defines
// how many hours should be added/subtracted (use minus for subtraction).

const
  HoursSpan = -3;   // amount of hours to add or subtract!!
  DateOutputFormat = 'yyyy-mm-dd hh.nn.ss';  // output date format!!
  HoursPerDay = 24;  // do not change this!!

var
  iYear, iMonth, iDay, iHour, iMin, iSec: Integer;
  Date, Time, DateTime: TDateTime;

procedure AddHours(var ADateTime: TDateTime; const ANumberOfHours: Integer);
begin
  ADateTime := ((ADateTime * HoursPerDay) + ANumberOfHours) / HoursPerDay;
end;

begin
  // extract date-time variables as integers
  iYear  := StrToIntDef(Copy(FileName, 1, 4), -1);
  iMonth := StrToIntDef(Copy(FileName, 6, 2), -1);
  iDay   := StrToIntDef(Copy(FileName, 9, 2), -1);
  iHour  := StrToIntDef(Copy(FileName, 12, 2), -1);
  iMin   := StrToIntDef(Copy(FileName, 15, 2), -1);
  iSec   := StrToIntDef(Copy(FileName, 18, 2), -1);

  // process only if all variables are correctly converted
  if (iYear >= 0) and (iMonth >= 0) and (iDay >= 0) and
     (iHour >= 0) and (iMin >= 0) and (iSec >= 0) then

  begin
    // create a new date-time variable
    Date := EncodeDate(iYear, iMonth, iDay);
    Time := EncodeTime(iHour, iMin, iSec, 0);
    DateTime := Date + Time;

    // add hours (use minus for subtracting)
    AddHours(DateTime, HoursSpan);

    // concatenate the rest of the filename and the new date
    FileName := Copy(FileName, 20, Length(FileName));
    FileName := FormatDateTime(DateOutputFormat, DateTime) + FileName;
  end

  // something went wrong
  else FileName := 'INVALID INPUT';
end.

Offline

#3 2009-10-04 14:56

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,370

Offline

#4 2009-10-04 19:05

wascko
Member
Registered: 2009-09-26
Posts: 2

Re: Changing dates by adding substracting a time-span

thanxs !
that's the one I was looking for.
I found it a few days ago (and quickly bookmarked it)

you know how it is when you'r looking for something you just know is out there somewhere, but don't manage to find it  roll

thanx for your reply

Offline

Board footer

Powered by FluxBB