Function overview
Prototype
PartialDate (
theDate )
Parameters
theDate
Description
Tags:
Date
User supplies a partial date and this converts to a valid date. Works for both month and years. For example 2/2009 returns 2/1/2009 which is a valid date. 2009 returns 1/1/2009.
Examples
Sample input
2009
Sample output
1/1/2009
Function code
/*
==================================================
03/21/2007 1.0 KLN Original Version
10/05/2007 1.1 KLN Updated Year Calculation On Month/Year Entry
10/08/2007 1.2 KLN Corrected Month/Year Calculation
==================================================
PURPOSE: To convert a "partial date" to a valid date. For Example 3/2007 would
return the date 3/1/2007, 2007 would return 1/1/2007. Allows users to enter as
text and come up with earliest date for that partial date.
==================================================
USER INPUTS
TheDate = The Date in text format
==================================================
*/
Case (
Trim(TheDate) = "Unknown" or IsEmpty ( TheDate ); GetAsDate("");
PatternCount ( TheDate ; "/" ) = 0; GetAsDate ("1/1/" & TheDate);
PatternCount ( TheDate ; "/" ) = 1; GetAsDate ( Left ( TheDate ; Position ( TheDate ; "/" ; 1 ; 1 ) - 1 ) & "/1/" & Right ( TheDate ; Length ( TheDate ) - Position ( TheDate ; "/" ; 1 ; 1 ) ));
PatternCount ( TheDate ; "/" ) = 2; GetAsDate (TheDate);
""
)
// ===================================
/*
This function is published on FileMaker Custom Functions
to check for updates and provide feedback and bug reports
please visit http://www.fmfunctions.com/fid/201
Prototype: PartialDate( theDate )
Function Author: Ken Newell (http://www.fmfunctions.com/mid/74)
Last updated: 03 February 2009
Version: 1.1
*/
// ===================================
/*__LITBR__==================================================__LITBR__ 03/21/2007 1.0 KLN Original Version__LITBR__ 10/05/2007 1.1 KLN Updated Year Calculation On Month/Year Entry__LITBR__ 10/08/2007 1.2 KLN Corrected Month/Year Calculation__LITBR__==================================================__LITBR__PURPOSE: To convert a "partial date" to a valid date. For Example 3/2007 would__LITBR__return the date 3/1/2007, 2007 would return 1/1/2007. Allows users to enter as__LITBR__text and come up with earliest date for that partial date.__LITBR__==================================================__LITBR__USER INPUTS__LITBR__ TheDate = The Date in text format__LITBR__==================================================__LITBR__*/__LITBR____LITBR__Case ( __LITBR__Trim(TheDate) = "Unknown" or IsEmpty ( TheDate ); GetAsDate("");__LITBR____LITBR__PatternCount ( TheDate ; "/" ) = 0; GetAsDate ("1/1/" & TheDate); __LITBR____LITBR__PatternCount ( TheDate ; "/" ) = 1; GetAsDate ( Left ( TheDate ; Position ( TheDate ; "/" ; 1 ; 1 ) - 1 ) & "/1/" & Right ( TheDate ; Length ( TheDate ) - Position ( TheDate ; "/" ; 1 ; 1 ) ));__LITBR____LITBR__PatternCount ( TheDate ; "/" ) = 2; GetAsDate (TheDate);__LITBR____LITBR__""__LITBR__ )__LITBR____LITBR__// ===================================__LITBR__/*__LITBR____LITBR__ This function is published on FileMaker Custom Functions__LITBR__ to check for updates and provide feedback and bug reports__LITBR__ please visit http://www.fmfunctions.com/fid/201__LITBR____LITBR__ Prototype: PartialDate( theDate )__LITBR__ Function Author: Ken Newell (http://www.fmfunctions.com/mid/74)__LITBR__ Last updated: 03 February 2009__LITBR__ Version: 1.1__LITBR____LITBR__*/__LITBR__// ===================================
Login or register to comment
Create a new account with fmcustomfunctions.com or login to post a comment.
Comments
03 February 2009
07 February 2009
Is there a format handled by this function and not the other one?
07 February 2009
(Edited by Fabrice on 07/02/09 )
07 February 2009
08 February 2009
the only problem with those type of CF is that you can't use them in a real date field, due to the fact that FileMaker validates the date BEFORE evaluating the CF.
08 February 2009
I probably should add notes to say that it returns text and if you want to use as a date wrap in a GetAsDate ( ) and supports mm/dd/yyyy format like Genx pointed out. I will be the first to admit this was a quick and dirty solution to a need that I had. However in FM the beauty is so many things can be done in different ways each with their own pros and cons and has new features are added things can always be updated on how to do it better or faster or with more option. If I was to redo I probably would use the CF that Fabrice posted which has more options
08 February 2009
Ken, I don't think that's the point Daniele was getting at. It was more the fact that because FileMaker runs the validation on the data entered based on the type of the field BEFORE running the CF, you are going to get a datatype mismatch error (with either your or Fabrices functions) if you try to enter a "quick" or "partial" date into an actual date field (vs a loosely typed text field) in the suggested format.
(Edited by Genx on 08/02/09 )
14 February 2009