ScriptTwoDigitYear

From 40tude Dialog Wiki

I found this script in a post by Andreas Oeser in de.comm.software.40tude-dialog. This will shorten the year in the date column to 2 digits. i.e. instead of '2004', '04'. You will have to change the value in 'const Idx=4;' to whichever column number matches your date/time column. Be aware that the '+/-' column doesn't count. The more inventive among us can surely use this script to shorten the date column even more.


See how the date column maybe looks like, if you use one of the following scripts:

Datumspalte.png


Please read the Painting script warning page before trying out one of these scripts.

program OnArticleListPaint;

const Idx=4; //Position of the date/time column.

function
OnArticleListPaint(PaintString:widestring;ColumnIndex:integer):widestring;
begin
if ColumnIndex = Idx then
   PaintString := Copy(PaintString, 1, 6) + Copy(PaintString, 9, 8);

result:=paintstring;
end;

begin
end.

UPDATE! Here are two more customizable version (e.g. to remove also the seconds):

one from Maria Luisa C. and the other from Antonio 'Gandalf' Favata.
And a third one, just a more usable version according to my first try. Andreas "Penny" Oeser 

From Maria Luisa C:

program OnArticleListPaint;
const

 colDate=5; // in the headers panel count the columns from left
            // to right starting from 0 and write here the
            // number of the coulumn Date

function
OnArticleListPaint(PaintString:WideString;ColumnIndex:Integer):WideString;

var
 n: Integer;
 tmpString: WideString;

begin

 case ColumnIndex of
  colDate:
   begin
    tmpString := PaintString;
    n:=length(PaintString);
   if ((n=16) or (n=17)) then  // two digits year
   begin
    PaintString := Copy(PaintString, 1, 9);
    case n of
     16:
     PaintString := PaintString + ' ' + Copy(tmpString, 10, 4);
     17:
     PaintString := PaintString + ' ' + Copy(tmpString, 10, 5);
    end;
   end
   else  // four digits year
   begin
    PaintString := Copy(PaintString, 1, 6) + Copy(PaintString, 9, 3);
    case n of
     19:
     PaintString := PaintString + Copy(tmpString, 12, 5);
     18:
     PaintString := PaintString + ' ' + Copy(tmpString, 12, 4);
     //if you want hours from 0 to 9 starting with 0, in the above line
     //put a 0 inside ' ' instead of a space

    end; //case
   end; //if
 end; //case
end;
result:=PaintString;
end;

begin
end.


From Antonio 'Gandalf' Favata:

program OnArticleListPaint;

 const

  colDate = 3; //count your columns from left to right starting from 0
               //and write here the number of the column Date;

  removeYear = true;      //set this to false if you don't want to remove the year
  removeSeconds = true;   //set this to false if you don't want to remove the seconds
  removeLeading0s = true; //set this to false if you don't want to remove the leading
                          //zero from the day, month and hour strings

 function OnArticleListPaint(PaintString:widestring;ColumnIndex:integer):widestring;

 var
  x: Integer;
  tmpDate, tmpTime, day, month, year, h, m, s, dateSeparator, timeSeparator:
   WideString;

 begin

  case ColumnIndex of
   colDate:
    begin
     x := pos(' ', paintstring);

     tmpDate := copy(paintstring, 1, x-1);
     tmpTime := copy(paintstring, x+1, 8);

     day := copy(tmpDate, 1, 2);
     if removeLeading0s and (copy(day, 1, 1) = '0') then
        day := copy(day, 2, 1);

     dateSeparator := copy(tmpDate, 3, 1);
     // uncomment the following line to use your own separator
     // dateSeparator := '~';

     month := copy(tmpDate, 4, 2);
     if removeLeading0s and (copy(month, 1, 1) = '0') then
        month := copy(month, 2, 1);

     year := copy(tmpDate, 7, x-6);

     h := copy(tmpTime, 1, 2);
     if removeLeading0s and (copy(h, 1, 1) = '0') then
        h := copy(h, 2, 1);

     timeSeparator := copy(tmpTime, 3, 1);
     // uncomment the following line to use your own separator
     // timeSeparator := '~';

     m := copy(tmpTime, 4, 2);
     s := copy(tmpTime, 7, 2);

     paintstring := day + dateSeparator + month;

     if not removeYear then
        paintstring := paintstring + dateSeparator + year;

     paintstring := paintstring + ' ' + h + timeSeparator + m;

     if not removeSeconds then
        paintstring := paintstring + timeSeparator + s;

    end;
  end; //case

 result:=paintstring;
 end;

 begin
 end.


From Andreas "Penny" Oeser, Just another Version

program OnArticleListPaint;             
{
Format the DATESTR Constant with the following format specifiers and set the Idx 
 Const to the right column (+/- doesn't count)
d 	  Displays the day as a number without a leading zero (1-31).
dd 	  Displays the day as a number with a leading zero (01-31).
ddd 	  Displays the day as an abbreviation (Sun-Sat) 
dddd 	  Displays the day as a full name (Sunday-Saturday).
m 	  Displays the month as a number without a leading zero (1-12). 
          If the m specifier immediately follows an h or hh specifier, 
          the minute rather than the month is displayed.
mm 	  Displays the month as a number with a leading zero (01-12). 
          If the mm specifier immediately follows an h or hh specifier, 
          the minute rather than the month is displayed.
mmm 	  Displays the month as an abbreviation (Jan-Dec).
mmmm 	  Displays the month as a full name (January-December).
yy 	  Displays the year as a two-digit number (00-99).
yyyy 	  Displays the year as a four-digit number (0000-9999).
h 	  Displays the hour without a leading zero (0-23).
hh 	  Displays the hour with a leading zero (00-23).
n 	  Displays the minute without a leading zero (0-59).
nn 	  Displays the minute with a leading zero (00-59).
s 	  Displays the second without a leading zero (0-59).
ss 	  Displays the second with a leading zero (00-59).
am/pm 	  Uses the 12-hour clock for the preceding h or hh specifier, and displays 'am' 
          for any hour before noon, and 'pm' for any hour after noon. The am/pm specifier 
          can use lower, upper, or mixed case, and the result is displayed accordingly.
a/p 	  Uses the 12-hour clock for the preceding h or hh specifier, and displays 'a' 
          for any hour before noon, and 'p' for any hour after noon. The a/p specifier 
          can use lower, upper, or mixed case, and the result is displayed accordingly.
any other character is displayed as-is and do not affect formatting

e.g. DATESTR='yy/m/d h-n'; //Shows 04/3/17 9-3
     DATESTR='dddd, dd. mmmm yyyy hh:nn:ss'; //Shows Wednesday, 17. March 2004 23:23:20
     DATESTR='dd.mm.yy hh:nnam/pm'; //Shows 17.03.04 09:15pm
}

const Idx=4; 
      DATESTR='dd.mm.yy hh:nn';
      TodayStr='Heute'; //If filled with a String, todays date will be replaced by the String
                        //If string is empty ('') todays date display like in the DATESTR

function OnArticleListPaint(PaintString:widestring;ColumnIndex:integer):widestring; 
begin     
  if ColumnIndex = Idx then begin
    PaintString := FormatDateTime(DATESTR, StrToDateTime(PaintString));
    if (FormatDateTime('dd.mm.YY', StrToDateTime(PaintString)) = FormatDateTime('dd.mm.YY', DATE)) 
    and not (TodayStr = '') then begin
      PaintString := TodayStr + ' ' + FormatDateTime('hh:nn', StrToDateTime(PaintString));
    end;
  end;
  result := PaintString;
end;
begin
end.