PartialDate ( )

Function stats

Average user rating
74
201
9999
Support
FileMaker 7.0 +
Date posted
03 February 2009
Last updated
03 February 2009
Version
Recursive function
No

Author Info
 Ken Newell

3 functions

Average Rating None

author_avatar



 

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

*/
// ===================================

 

Comments

Genx
03 February 2009



You should probably make a note that this supports mm/dd/yyyy format only.
  General comment
Fabrice
07 February 2009



did you have a look at this one : http://www.fmfunctions.com/fname/fastdateinput
Is there a format handled by this function and not the other one?
  General comment
Fabrice
07 February 2009



sorry, getting used to this new trackpad... clicks fast ! :)
(Edited by Fabrice on 07/02/09 )
  General comment
Ken Newell
07 February 2009



Wow a mouse on steroids. I have not looked at your function in details but it looks like it handles a lot of different uses. My was written for a very specific need and I did not build a lot of extras into it. Use whatever meets your need.
  General comment
Daniele Raybaudi
08 February 2009



Hi Ken and Fabrice

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.
  General comment
Ken Newell
08 February 2009



Daniele,

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
  General comment
Genx
08 February 2009



Hi Guys,

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 )
  General comment
Michael W.
14 February 2009



And in comes FM10. :-) You can use this function with a script trigger on a date field that will run prior the validation of the field.
  General comment

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (28)
XML  (27)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Interface  (15)
Layout  (15)
Text  (14)
Variables  (13)
Filter  (12)
Layout Objects  (11)
Design  (10)
Array  (8)