S1:='20140101'.
S2:='20140908'.
I think automatic calculation in Delphi minus the difference between the number of days of s1 and s2 add this number to me from the database query to another date above the s3,
Please grant instruction!
CodePudding user response:
Converts the date type, then use DaysBetween (reference DateUtils unit) function calculation of two datesCodePudding user response:
var S1, S2: string;
The begin
S1:='20140101'.
S2:='20140908'.
FieldByName (" date "). AsString:=FormatDateTime (' yyyyMMdd 'StrToDate (S2) - StrToDate (S1));
end;
For reference only.
CodePudding user response:
Error: '20140908' is not a valid date.CodePudding user response:
S:='20140908'.Insert (' - 's, 5);
Insert (' - 's, 8).
Formation - dd yyyy - MM
Then strtodate
Then daysbetween
CodePudding user response:
The function cnStrToDateTime (AStr: string) : TDateTime;Var
Setting: TFormatSettings;
The begin
Setting:=TFormatSettings. Create (LOCALE_USER_DEFAULT);
Setting. ShortDateFormat:='yyyymmdd';
Setting. DateSeparator:='-';
Setting. TimeSeparator:=':';
Setting. LongTimeFormat:='hh: nn: ss. Z';
Result:=StrToDateTime (AStr, Setting);
end;
IncDate (DateBetween (cnStrToDateTime (' 20160101 '), cnStrToDateTime (' 20150203 ')))
CodePudding user response:
IncDate (OtherDate cnStrToDateTime (' 20160101 ') - cnStrToDateTime (' 20150203 '))CodePudding user response:
The function cnStrToDateTime (AStr: string) : TDateTime;Var
Setting: TFormatSettings;
The begin
Setting:=TFormatSettings. Create (LOCALE_USER_DEFAULT);
Setting. ShortDateFormat:='yyyymmdd';
Setting the DateSeparator:=';
Setting. TimeSeparator:=':';
Setting. LongTimeFormat:='hh: nn: ss. Z';
Result:=StrToDateTime (AStr, Setting);
end;
IncDate (OtherDate cnStrToDateTime (' 20160101 ') - cnStrToDateTime (' 20150203 '))
CodePudding user response: