Board index » delphi » Month Query

Month Query

Hi,
How can I convert a date feild into a string and then just compare
the month value with a variable supplied by user a run time?

Im using paradox table if that matters!

THANX
Jay

 

Re:Month Query


Shaggy,

I'd think that the simplest way to do this at the client machine would
be:

function CompareMonth(UserMonth: Byte): Boolean;
var
  StoredMonth: Byte;
begin

  if not Query1.FieldByName('StoredDate').IsNull then
    StoredMonth := StrToInt(FormatDateTime('m',
Query1.FieldByName('TheDate').AsDateTime))
  else // This would force a FALSE return if no date were stored
    StoredMonth := 0;

  Result := (StoredMonth = UserMonth);

end;

HTH - Mike

Quote
Shaggy wrote:

> Hi,
> How can I convert a date feild into a string and then just compare
> the month value with a variable supplied by user a run time?

> Im using paradox table if that matters!

> THANX
> Jay

Re:Month Query


I'm sorry,

Quote
>   if not Query1.FieldByName('StoredDate').IsNull then
>     StoredMonth := StrToInt(FormatDateTime('m',
> Query1.FieldByName('TheDate').AsDateTime))

This should have read Query1.FieldByName('StoredDate') in both cases :)

- Mike

Re:Month Query


Quote
In article <01bd86d5$a5303d40$b12f31ca@mother>, Shaggy wrote:
> How can I convert a date feild into a string and then just compare
> the month value with a variable supplied by user a run time?

In code, or in the query?

In a query:

    SELECT * FROM EMPLOYEE where EXTRACT (MONTH FROM HIRE_DATE) = :RequestedMonth

In code:

    var
      MM, DD, YY: Word;

    DecodeDate (Query1HireDate.AsDateTime, yy, mm, dd);
    If mm = RequestedMonth then ...

Quote

> Im using paradox table if that matters!

Best place for paradox questions is the database.desktop newsgroup.

Other Threads