×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Comparing Date and Strings

Comparing Date and Strings

Comparing Date and Strings

(OP)
How do I compare a date string in yyyymmdd format to the current date?

RE: Comparing Date and Strings

If you're using Pervasive.SQL 9.5, you can use the new scalar function DATEDIFF.  Check out the scalar function docs in the SQL Engine Reference at http://www.pervasive.com/library/docs/psql/950/sqlref/sqlref-06-4.html

DATEADD, DATENAME, and DATEPART are also new, as well as a new datatype called DATETIME.

Linda
Pervasive Software

RE: Comparing Date and Strings

(OP)
I am using 9.5.  I am entering the following

select * from "adheader"
  where DATEDIFF(day,LastInsertDate,Current_Date())>0

I get

[LNA][Pervasive][ODBC Engine Interface]Expression evaluation error.

2ndly, the LastInsertDate field is in yyyymmdd string format - no hypens. Is this going to work?

Thanks

RE: Comparing Date and Strings

You're going to need to convert (or mask) the field to a date so you can use data functions.  
So your select should look like:

CODE

select * from "adheader"
  where DATEDIFF(day, convert(left(LastInsertDate,4) + '-' + substring(LastInsertDate,5,2) + '-' + right(LastInsertDate,2) , sql_date),Current_Date())>0

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com

RE: Comparing Date and Strings

Sorry, bad term in there. "Mask" was an old term.  

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com

RE: Comparing Date and Strings

(OP)
Here is what I have in the sql statement"
  L := form1.tbCLient.FieldByName('ClientNumber').asString;
  form1.qAds.SQL.Clear;
  form1.PvSQLSession1.ServerName := 'Btrieve';
  form1.qAds.DatabaseName := 'LPV8OE';
  form1.qAds.SQL.Add ('select clientnumber, pubnumber, adnumber,entryyear,regarding, lastinsertdate from adheader');
  form1.qAds.SQL.Add (' where clientnumber = ' + quotedstr(L) + 'and');
  form1.qAds.SQL.Add (' KBI<>' + quotedstr('Y') + 'and InvoiceNumber=' + quotedstr('') + 'and' );
  form1.qAds.SQL.Add ('  DateDiff(day,convert(left(LastInsertDate,4) + '-' + substring(LastInsertDate,5,2) + '-' + right(LastInsertDate,2), sql_date),Current_Date() )>0';
  form1.qAds.SQL.Add ('order by pubnumber,entryyear,adnumber');
  form1.qAds.SQL.Text;
  form1.qAds.Open;

The problem is the compiler doesn't like the 2nd dash:
[Error] Client.pas(405): Operator not applicable to this operand type

Is there a line length limit and if so how do I continue on the next line?   Thanks

RE: Comparing Date and Strings

You're getting that error because Delphi treats single quotes as the string delimiter. You need to escape the single quotes.  It should look like:

CODE

  form1.qAds.SQL.Add ('  DateDiff(day,convert(left(LastInsertDate,4) + '-' + substring(LastInsertDate,5,2) + '-' + right(LastInsertDate,2), sql_date),Current_Date() )>0');
  form1.qAds.SQL.Add (' order by pubnumber,entryyear,adnumber');

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close