Find date in TEXT field & remove if older than current date

emulsified
Member Posts: 139
Does anyone have any suggestions on how to search a TEXT field for any date, check it against the current date to see if it is in the past or older than the current date?
I have a TEXT field on my item card named ETADate that we use to put information like "ETA 12/20/2010" or "ETA 12-20-10 NEW ITEM".
To clarify things I will be setting to blank when an older date is found:
ETADate := '';
// Save the modification, commit blah blah
I'm going to create a processing only report to clean up old ETADate information and was wondering if anyone had an easy way to find an older date in a string?
I have a TEXT field on my item card named ETADate that we use to put information like "ETA 12/20/2010" or "ETA 12-20-10 NEW ITEM".
To clarify things I will be setting to blank when an older date is found:
ETADate := '';
// Save the modification, commit blah blah
I'm going to create a processing only report to clean up old ETADate information and was wondering if anyone had an easy way to find an older date in a string?
Half-empy or half-full how do you view your database?
Thanks.
Thanks.
0
Answers
-
You could try something like this
This assuming that the Date portion is after the first blank.DateStr := ETAField; IF STRPOS(DateStr,' ') > 0 THEN BEGIN DateStr := COPYSTR(DateStr,STRPOS(DAteStr,' '); IF STRPOS(DateStr,' ') > 0 THEN BEGIN DateStr := COPYSTR(DateStr,1,STRPOS(DAteStr,' ') ; END; DateStr := DELCHR(DateStr,'=',DELCHR(DateStr,'=','0123456789'); //This will remove all non-numerics IF EVALUATE(DateVar,DateStr) THEN IF DateVar <= TODAY THEN ETAField := '';
DateStr is Text and DateVar is Date
Hope this points you in the right direction0 -
I haven't tried your suggestion yet, but let me see if I understand your code correctly:
1. In your code you are saying IF the position of the first blank space is greater than 0 then copy from that position into DateStr.
2. So DateStr was "ETA 12-10-10 NEW ITEM" and would become "12-10-10 NEW ITEM".
3. Then you run DateStr through again and it copies from position 1 of DateStr to the position of the next blank space so I should end up with "12-10-10".
4. After that it looks like you're using DELCHR to remove anything that is not number like the "-" hyphens or "/" slashes normally found in date strings.
5. Finally you are using EVALUATE on DateStr which is currently "121010" to put it into DateVar as a valid date for comparison.
Did I follow this correctly?
I think I got it now, but what it I have blank spaces at the beginning of the field and also before and after the actual date?
I'm going to give this a try:DateStr := ETAField; IF STRPOS(DateStr,' ') > 0 THEN BEGIN DateStr := COPYSTR(DateStr,STRPOS(DAteStr,' ')); IF STRPOS(DateStr,' ') > 0 THEN BEGIN DateStr := COPYSTR(DateStr,1,STRPOS(DAteStr,' ')); END; DateStr := DELCHR(DateStr,'=',' ')); // added to remove any additional whitespaces before or after the date, but I guess the next line would do that anyway DateStr := DELCHR(DateStr,'=',DELCHR(DateStr,'=','0123456789')); //This will remove all non-numerics IF EVALUATE(DateVar,DateStr) THEN IF DateVar <= TODAY THEN ETAField := ''; // commit
Half-empy or half-full how do you view your database?
Thanks.0 -
if spaces are an issue you can find the first dash or slash & count back 2 positions0
-
You are spot on but the delchr line will delete anything that is not numeric so there will be no spaces either.
If there are spaces in the begining of the field you can replace the datestr := statement to
DateStr := DLECHR(ETAField,'<>',' ');
This will delete all the leading and trailing spaces.0 -
Why don't you make that field a date type field, and add a field called "ETA Comment" or something like that. It will be much easier to program that way, plus you will have the capability to filter.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions