Jump to content

This topic is 7110 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi,

I have a membership database with several date fields.

Does anymore know how to have the dates that i enter automatically change and add the '/' separator.

ie: enter 101105 and it automatically changes to 10/11/05

Any help would be most appreciated.

I have attached the database for reference.

Kindest Regards,

Shane.

101105.zip

Posted

Hi

I have attached your file with the custom function DataFormattata(text).

Look at the day of birth definition ! :

You can enter text in these ways:

ggmmaa; gg/mm/aa; ggmmaaaa; gg/mm/aaaa

and the result will be always:

gg/mm/aaaa

FormattedDate.zip

Posted

Hi Shane,

Hopefully these dates (and this Birth Date?) aren't important. You are giving up your true dates and this is a big price to pay. At LEAST have another true date field with auto-enter (Replace) based upon that text date (to attempt to give you a real date). Because you will NOT be able to use this pseudo-date in date calculations (such as calculating their age), sorting it by date or consistent searching.

BTW, custom function calculaton removes the ability to type dates the easy way we're all used to ... if you type 1/1 (assuming the current year) it produces errore. Users are USED to typing a dash or slash and you are not doing them a service by ignoring standard 'computer' rules on dates. And those Users that are good (and follow standard computer rules; typing 1/1/2005) will be punished with a big fat ? in that DOB field of yours. You won't be able to modify that Custom Function either because you don't have Developer. And this had better be the file you plan to continue your design in because you can't transfer it. :crazy2:

I just wanted to be sure you understood the cost of your choice by ignoring true-date logic. :wink2:

Hmmm, reminds me of a saying ... "Sometimes we're so busy figuring out if we CAN do something that we don't stop to consider whether we SHOULD." Said by a chaos-theory guy on some TV show but it stuck in my mind ...

LaRetta

Posted

Thank you LaRetta !

I never knew that you can write 1/1 and automatically have 01/01/2005 ! :

So now I'll go to modify my CF ! :

BTW it is true that the calc gives a pseudo-date, but it is olso true that you (the programmer) know that !

Because you will NOT be able to use this pseudo-date in date calculations (such as calculating their age)

And if you know, you'll write for an Age calc:

Year ( Get ( CurrentDate ) ) - Year(GetAsDate ( Date Of Birth )) - ( Get ( CurrentDate ) < Date ( Month(GetAsDate ( Date Of Birth )) ; Day(GetAsDate ( Date Of Birth )) ; Year ( Get ( CurrentDate ) ) ) )

Posted

So this is the new custom function:

_____________________________________________

/*

Custom Function: FormatAsDate

Author:

Daniele Raybaudi

Format:

FormatAsDate ( text )

Parameter:

text - any text expression or text field

Accept inserted text as: g/m; gg/m; g/mm; gg/mm; gmaa; g/m/aa; g/mm/aa; gg/m/aa; ggmmaa; gg/mm/aa; g/m/aaaa; ggmmaaaa; g/mm/aaaa; gg/m/aaaa; gg/mm/aaaa;

Result:

Pseudo-Date

Description:

Returns the given text as the valid complete formatted date: gg/mm/aaaa;

BTW this isn't a recursive function, so you can use it as a calc !

10 november 2005

*/

Let ([

LD = Length ( text );

F = Filter ( text ; "-/" );

LF = Length ( F );

F2 = Filter ( text ; "-/0123456789" );

LF2 = Length ( F2 )

];

Case(

LD ≠ LF2;"error";

LF > 2 ; "error";

LF ≥ 1 ; GetAsDate (text);// g/m or gg/m or g/mm or gg/mm or g/m/aa or g/mm/aa or gg/m/aa or gg/mm/aa or g/m/aaaa or g/mm/aaaa or gg/m/aaaa

LF2 = 8 ; GetAsDate ( Left( text ; 2 ) & "/" & Middle(text ; 3 ; 2) & "/" &Right(text ; 4 ));// ggmmaaaa

LF2 = 6 ; GetAsDate ( Left( text ; 2 ) & "/" & Middle(text ; 3 ; 2) & "/" &Right(text ; 2 ));// ggmmaa

LF2 = 4 ; GetAsDate ( Left( text ; 1 ) & "/" & Middle(text ; 2 ; 1) & "/" &Right(text ; 2 ));// gmaa

LF2;"error";

GetAsDate ( "" )

)

)

________________________________________________

and a new attached file

FormattedDate.zip

Posted (edited)

Nice but...

Lord forbid the person shares this data (or file) with someone with different system date settings. Because it will break on them. I hope Shane doesn't ever want to display this field (using Field Format) as Saturday, March 23rd either (or use it in merge fields)!! And I hope Shane offers more protection than a simple 'error' in the field (or a ? which you can also get when you CF doesn't catch the error - and it doesn't catch them all) because Users won't notice (or correct) it!! At least FM INSISTS they correct or revert on REAL dates!! As I said, I hope none of these date fields are important and I hope he alots extra time to constantly deal with their convolution. :shocked:

What you say may be true, Daniele, ie, the Developer will know to always (continually for eternity) have to remember to convert every calculation or situation which expects a true date; but 1) Shane indicated he's a beginner (he would not have known this) and 2) he doesn't have Developer.

My question to you is: Who are you posting this for? BTW, you don't need a Custom Function for your calculation at all, so I guess Shane can use it anyway...

At least change the field name Date Of Birth to TextDateOfBirth so (in the future forevermore) the 'Developer' will remember to deal with its inadequacy as a date. And the 'Developer' will need to remember to tweak it for sorting, ditch it for searching, and call you to change the custom function for them. :wink2:

LaRetta

Edited by Guest
Posted

Hi, LaRetta

I agree with you for your worries...

But we have gived some guidance to Shane and she wished that kind of calc !

And now she can modify the function (as it isn't recursive).

I can't make something better :

Lord forbid the person shares this data (or file) with someone with different system date settings. Because it will break on them.

Here I think you are wrong, because it depends by how you write the text: if you write 10112005 as an American people, you'll end with october 11 (as you expected); European people will end with november 10, as they expected.

Posted

And those Users that are good (and follow standard computer rules; typing 1/1/2005) will be punished with a big fat ?

And with this improved version, the big fat ? never appears !

-------------------------------------------------

/*

Custom Function: FormatAsDate

Author:

Daniele Raybaudi

Format:

FormatAsDate ( text )

Parameter:

text - any text expression or text field

Accept inserted text as: g/m; gg/m; g/mm; gg/mm; gmaa; g/m/aa; g/mm/aa; gg/m/aa; ggmmaa; gg/mm/aa; g/m/aaaa; ggmmaaaa; g/mm/aaaa; gg/m/aaaa; gg/mm/aaaa;

Result:

Pseudo-Date(text): to use the result for date calculation, you'll need GetAsDate(Result)

Description:

Returns the given text as the valid complete formatted date: gg/mm/aaaa;

any invalid entry (not a date) returns: error

BTW this isn't a recursive function, so you can use it as a calc !

november 11, 2005

*/

Let ([

LD = Length ( text );

F = Filter ( text ; "-/" );

LF = Length ( F );

F2 = Filter ( text ; "-/0123456789" );

LF2 = Length ( F2 )

];

Case (

LD = 0 ; "" ;

LD ≠ LF2 ; "error" ;

LF > 2 ; "error";

LF ≥ 1 and IsValid ( GetAsDate ( text )) ; GetAsDate ( text );// g/m or gg/m or g/mm or gg/mm or g/m/aa or g/mm/aa or gg/m/aa or gg/mm/aa or g/m/aaaa or g/mm/aaaa or gg/m/aaaa

LF2 = 8 and IsValid ( GetAsDate ( Left ( text ; 2 ) & "/" & Middle ( text ; 3 ; 2 ) & "/" & Right( text ; 4 ))) ; GetAsDate ( Left ( text ; 2 ) & "/" & Middle ( text ; 3 ; 2) & "/" & Right( text ; 4 ));// ggmmaaaa

LF2 = 6 and IsValid ( GetAsDate ( Left ( text ; 2 ) & "/" & Middle ( text ; 3 ; 2 ) & "/" & Right( text ; 2 ))) ; GetAsDate ( Left ( text ; 2 ) & "/" & Middle ( text ; 3 ; 2) & "/" & Right( text ; 2 ));// ggmmaa

LF2 = 4 and IsValid ( GetAsDate ( Left ( text ; 1 ) & "/" & Middle ( text ; 2 ; 1 ) & "/" & Right( text ; 2 ))) ; GetAsDate ( Left ( text ; 1 ) & "/" & Middle ( text ; 2 ; 1) & "/" & Right( text ; 2 ));// gmaa

"error"

)

)

-------------------------------------------------

BTW Shane, you have to know that with FM8 a right real date entry is only two click away ! :

This topic is 7110 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.