Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p><strong>edit:</strong> code for the 3rd comment below;</p> <pre><code>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; </code></pre> <p><hr /> <strong>edit:</strong> With calculated fields;</p> <p>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 <a href="https://stackoverflow.com/questions/2917336/insert-number-of-days-of-year-months-days-of-month/2921351#2921351">answer</a>, 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".</p> <pre><code>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; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload