Probably I'm missing the question but in case I'm not, you can find what you need in "DateUtils.pas". It has functions like "DayOfTheYear", "MonthOfTheYear", "DayOfTheMonth", "DayOfTheWeek" and many more. I think you're gonna store them in different fields, but there might be a probability that you don't need to store them at all; the database you're using might supply similar functionality, in that case you can construct your queries to supply the filtering/ordering you need.
edit: code for the 3rd comment below;
procedure TForm1.Button1Click(Sender: TObject);
var
Year, DaysInYear: Word;
FirstDay, i: Integer;
begin
Year := StrToInt(ano.Text);
DaysInYear := DaysInAYear(Year);
diasano.Text := IntToStr(DaysInYear);
FirstDay := Trunc(EncodeDate(Year, 1, 1));
for i := FirstDay to FirstDay + DaysInYear - 1 do begin
Planeamento.Append;
Planeamento.FieldByName('diasAno').Value := DayOfTheYear(i);
Planeamento.FieldByName('Month').Value := LongMonthNames[MonthOfTheYear(i)];
Planeamento.FieldByName('DayOfMonth').Value := DayOfTheMonth(i);
Planeamento.FieldByName('DayOfWeek').Value := LongDayNames[DayOfTheWeek(i)];
Planeamento.Post;
end;
end;
edit: With calculated fields;
For the below example the table has five columns instead of four. Let's name the first column 'Date'. This column is the only column to store data and will hold the Date (as per ldsandon's answer, since by storing the date instead of day-number, you won't have to keep track of what table represents what year, and calculations will be simpler).
The other four columns are exactly the same as in the question, except that they all are "calculated fields".
procedure TForm1.Button1Click(Sender: TObject);
var
Year, DaysInYear: Word;
FirstDay, i: Integer;
begin
Year := StrToInt(ano.Text);
DaysInYear := DaysInAYear(Year);
diasano.Text := IntToStr(DaysInYear);
FirstDay := Trunc(EncodeDate(Year, 1, 1));
for i := FirstDay to FirstDay + DaysInYear - 1 do begin
Planeamento.Append;
Planeamento.FieldByName('Date').Value := i;
Planeamento.Post;
end;
end;
procedure TForm1.PlaneamentoCalcFields(DataSet: TDataSet);
var
Date: TDateTime;
begin
Date := DataSet.FieldByName('Date').AsDateTime;
DataSet.FieldByName('diasAno').AsInteger := DayOfTheYear(Date);
DataSet.FieldByName('Month').AsString := LongMonthNames[MonthOfTheYear(Date)];
DataSet.FieldByName('DayOfMonth').AsInteger := DayOfTheMonth(Date);
DataSet.FieldByName('DayOfWeek').AsString := LongDayNames[DayOfTheWeek(Date)];
end;