function getdatefrom(strs: string): string;
var
m_year, m_weekday, m_num_weekday, m_month: string;
date_tmp, BDate: TDateTime;
masiv: StringArray;
const
PUNCT = [':', ';'];
begin
if TryStrToDate(strs, BDate) then
result := strs
else
Begin
try
SetLength(masiv, 4);
masiv := split(strs, PUNCT);
m_num_weekday := masiv[0];
m_weekday := masiv[1];
m_month := masiv[2];
finally
if m_num_weekday = '' then
m_num_weekday := inttostr(WeekOfTheMonth(now));
if m_weekday = '' then
m_weekday := inttostr(dayOfTheMonth(now));
if m_month = '' then
m_month := inttostr(Monthoftheyear(now));
end;
// sShowMessage (m_num_weekday+' -'+m_weekday+' -'+m_month);
if length(masiv) = 4 then
m_year := masiv[3]
else
m_year := inttostr(YearOf(now));
date_tmp := StrToDate(FormatDateTime('dd.mm.yyyy',StrToDate('01.' + m_month + '.' + m_year)));
date_tmp:=IncDay(GetMonday(IncWeek(date_tmp,StrToInt(m_num_weekday)-1)),StrToInt(m_weekday)-1);
result := (DateToStr(date_tmp));
End;
end;
function GetMonday(RefDay: TDate): TDate;
var
DoW: Integer;
DateOffset: Integer;
begin
DoW := DayOfWeek(RefDay);
// Montag der Woche
if DoW = 1 then
DateOffset := -6
else
DateOffset := DoW - 2;
result := RefDay - DateOffset;
end;