-
02-23-2012, 10:46 AM #1Limited Access Member
- Location:
- Winnipeg, Canada
- Join Date
- Feb 2006
- Posts
- 19
- FM Version
- FileMaker...FMP v10
- Skill Level
- Developer
- OS
- Windows & Mac
- Rep Power
- 0
Converting Partial Date (text) to searchable Date?
What Calculation, Let statement or Custom function can convert a text field "Dec/2011" into a searchable Date range.
In this case every record in the table has a field called Period (set by a script at time of importing data).
The Period field is Text and always contains Mth/Year, i.e. Dec/2011, Jan/2012....
Objective: to search for Periods within a Range as either:
Jun/2011...Nov/2011 or
6/1/2011...11/30/2011 or
2011/06/01...2011/11/30
robear
-
02-23-2012, 11:21 AM #2Moderator - Editor
- Location:
- New York (Manhattan) USA
- Join Date
- Aug 2006
- Posts
- 10,015
- FM Version
- 12, 10, 9, 8.5, 8, 7, 6, 5.5., 5, 4.1, 4, 3, 2.1, 1, II; & the old Nashoba versions. But not 11
- Skill Level
- Developer
- OS
- Windows & Mac
- Blog Entries
- 1
- Rep Power
- 10
Re: Converting Partial Date (text) to searchable Date?
Method A: Calculation field result type "date" defined as
Let ([
MonthName = Left (YourTextField; 3);
MonthStack = "Jan¶Feb&Mar¶Apr¶May¶Jun¶Jul¶Aug¶Sep¶Oct¶Nov¶D ec";
Cut = Middle (MonthStack; 1; Position (MonthStack; MonthName; 1; 1);
mon = PatternCount (Cut; "¶")+1;
yr = Right (YourTextField; 4)
];
Date (mon; 1; yr)
)
Search this calculation field using regular date ranges.
6/1/2011...11/30/2011
Method B: Calculation field result type "number" defined as
Let ([
MonthName = Left (YourTextField; 3);
MonthStack = "Jan¶Feb&Mar¶Apr¶May¶Jun¶Jul¶Aug¶Sep¶Oct¶Nov¶D ec";
Cut = Middle (MonthStack; 1; Position (MonthStack; MonthName; 1; 1);
mon = PatternCount (Cut; "¶")+1;
yr = Right (YourTextField; 4)
];
yr & Right ("0" & mon; 2)
Search this calculation field using this type of nomenclature:
201106...201111
-
02-23-2012, 11:30 AM #3Moderator - Editor
- Location:
- Southern California
- Join Date
- Mar 2006
- Posts
- 1,881
- FM Version
- Filemaker 11 Pro Advanced (11, 10, 9, 8)
- Skill Level
- Intermediate
- OS
- Windows & Mac
- Rep Power
- 10
Re: Converting Partial Date (text) to searchable Date?
Use a calculated field, text result **OR** a looping script that uses this calculation to populate a text field:Jun/2011...Nov/2011
Date (
Case (
Left (Text Date;3) = "Jan" ; "1" ;
Left (Text Date;3) = "Feb" ; "2" ;
Left (Text Date;3) = "Mar" ; "3" ;
Left (Text Date;3) = "Apr" ; "4" ;
Left (Text Date;3) = "May" ; "5" ;
Left (Text Date;3) = "Jun" ; "6" ;
Left (Text Date;3) = "Jul" ; "7" ;
Left (Text Date;3) = "Aug" ; "8" ;
Left (Text Date;3) = "Sep" ; "9" ;
Left (Text Date;3) = "Oct" ; "10" ;
Left (Text Date;3) = "Nov" ; "11" ;
Left (Text Date;3) = "Dec" ; "12" ) ; "1" ; Middle (Text Date;5;4))
& ".." &
Date (
Case (
Middle (Text Date;12;3) = "Jan" ; "1" ;
Middle (Text Date;12;3) = "Feb" ; "2" ;
Middle (Text Date;12;3) = "Mar" ; "3" ;
Middle (Text Date;12;3) = "Apr" ; "4" ;
Middle (Text Date;12;3) = "May" ; "5" ;
Middle (Text Date;12;3) = "Jun" ; "6" ;
Middle (Text Date;12;3) = "Jul" ; "7" ;
Middle (Text Date;12;3) = "Aug" ; "8" ;
Middle (Text Date;12;3) = "Sep" ; "9" ;
Middle (Text Date;12;3) = "Oct" ; "10" ;
Middle (Text Date;12;3) = "Nov" ; "11" ;
Middle (Text Date;12;3) = "Dec" ; "12" ) ; "1" ; Right (Text Date;4))
Gives this result which you can use to search a date range ---> 6/1/2011..11/1/2011
Since you did not specify days and those are needed (bold red above) you can tweak the equation. To get the last day of ANY month use this calculation: Date ((Month + 1; 1; Year)-1) Edit: ---> this is easier to get last day of any month ---> Date ( Month + 1 ; 0 ; Year)
-
02-23-2012, 02:12 PM #4Limited Access Member
- Location:
- Winnipeg, Canada
- Join Date
- Feb 2006
- Posts
- 19
- FM Version
- FileMaker...FMP v10
- Skill Level
- Developer
- OS
- Windows & Mac
- Rep Power
- 0
Re: Converting Partial Date (text) to searchable Date?
Hi
Not sure if I missed a piece but Method B (the desired nomenclature) throws an error:
"too many parameters" and highlites the colon at end of Cut line.
robear
-
02-23-2012, 03:23 PM #5Senior Moderator
- Location:
- Connecticut
- Join Date
- May 2001
- Posts
- 2,077
- FM Version
- FileMaker 10A Server 10
- Skill Level
- Developer
- OS
- Windows & Mac
- Rep Power
- 50
Re: Converting Partial Date (text) to searchable Date?
As long as "Dec/2011" is the only thing in the fieldWhat Calculation, Let statement or Custom function can convert a text field "Dec/2011" into a searchable Date range.
Use this Custom Function http://www.briandunning.com/cf/805
MonthNumber
Change the parameter to Month_Name, in the parameter area and as well in the calculation area.
since FM won't allow you to use MonthName because it is a FM command word.
Should be MonthNumber(Month_Name)
In your Calculation to draw the date out simply do this
GetAsDate(Date(MonthNumber ( YourTable::YourFieldYourTable ); 1 ; Right(YourTable::YourFieldYourTable;4) ) )
-
02-23-2012, 06:37 PM #6Moderator - Editor
- Location:
- Seattle, Washington USA
- Join Date
- Aug 2006
- Posts
- 578
- FM Version
- 8.5, 9, 10, 11
- Skill Level
- Developer
- OS
- Windows & Mac
- Rep Power
- 10
Re: Converting Partial Date (text) to searchable Date?
In order to be able to search in all of the ways that you list the calculation is going to have to return text, rather than date. Furthermore there will have to be many values in the field, separated by returns. In my opinion it would be better to use one of the solutions shown above to return a date e.g., 6/1/2011. Then script the search process so you can parse the search term to a variable. Regardless of the input format return only m/yyyy to the variable, or in the case of a range m/yyyy...m/yyyy. In this way you can find any day within the month even though all of the dates are actually on the first day.
-
02-23-2012, 07:43 PM #7Limited Access Member
- Location:
- Winnipeg, Canada
- Join Date
- Feb 2006
- Posts
- 19
- FM Version
- FileMaker...FMP v10
- Skill Level
- Developer
- OS
- Windows & Mac
- Rep Power
- 0
Re: Converting Partial Date (text) to searchable Date?
-
02-24-2012, 01:13 AM #8Limited Access Member
- Location:
- Winnipeg, Canada
- Join Date
- Feb 2006
- Posts
- 19
- FM Version
- FileMaker...FMP v10
- Skill Level
- Developer
- OS
- Windows & Mac
- Rep Power
- 0
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads - The answer to your question may be in one of these posts!
-
Converting Unix Date/number to Standard Date
By Answers in forum Calculations and Define FieldsReplies: 4Last Post: 02-16-2011, 07:04 PM -
Date Conversion - Text field to Date field
By mbroholt in forum FileMaker Pro 9Replies: 1Last Post: 01-05-2009, 11:09 PM -
Partial Text filtering in a portal
By odedd in forum Find, Sort and SearchReplies: 0Last Post: 03-20-2007, 10:17 AM -
converting text to date
By jadato in forum Calculations and Define FieldsReplies: 2Last Post: 05-06-2002, 08:00 PM -
Converting Calendar Date to Julian Date
By zekewalton in forum Calculations and Define FieldsReplies: 1Last Post: 03-16-2001, 11:23 AM



Reply With Quote





Bookmarks