Topic: How to Use the DaysBetween function in select sentence?

I want to query the record that Days Between <=30days ,so I use the script ,but there is a error :NO such function DaysBetween.How can I use the function correctly?
form2.TableGrid1.dbSQL := ('select name,indate from maintable where  DaysBetween(now,indate)<=30 ')

Re: How to Use the DaysBetween function in select sentence?

WHERE  indate >= date('now','-30 day')

Re: How to Use the DaysBetween function in select sentence?

thank you!but i cann't run the app with this script.please help me

     form2.TableGrid1.dbSQL := 'select name,indate from maintable where indate >= date('now','-30 day')';
     form2.TableGrid1.dbSQLExecute;

Re: How to Use the DaysBetween function in select sentence?

form2.TableGrid1.dbSQL := 'select name,indate from maintable where indate >= date(''now'',''-30 day'')';

5 (edited by sibprogsistem 2022-02-01 20:10:45)

Re: How to Use the DaysBetween function in select sentence?

Функция DaysBetween вычитает FromDate из ToDate, возвращая разность в целых днях.


var
  fromdate, toDate : TDateTime;

begin
  // Установка наших переменных дат
  fromDate := EncodeDateTime(2000, 02, 26, 10, 0, 0, 0);
  toDate   := EncodeDateTime(2000, 02, 29,  9, 0, 0, 0);

  // Отображение этих дат и дней между ними
  ShowMessage('С даты = '+DateTimeToStr(fromDate));
  ShowMessage('До даты = '+DateTimeToStr(toDate));
  ShowMessage('Целых дней = '+
              IntToStr(DaysBetween(toDate, fromDate))+' дней');
end;
Post's attachments

Attachment icon test.rar 2.4 kb, 190 downloads since 2022-02-01 

Re: How to Use the DaysBetween function in select sentence?

sparrow wrote:

form2.TableGrid1.dbSQL := 'select name,indate from maintable where indate >= date(''now'',''-30 day'')';

thank.it work well.