1 2 Previous Next 16 Replies Latest reply on Oct 23, 2012 9:48 PM by Malcolm

    Calculation getting Year Only

    louie23

      Hello fellow filemaker user...

      Need your assistance please.

       

      1. How to get current year only as output in number?

      2. How to get last two digits in number the year of birth?

       

      Thank you!

        • 1. Re: Calculation getting Year Only
          MarcDolley

          1. Year(Get(CurrentDate))

          2. Right(Year of Birth; 2)

           

          Make sure both calculations are set to return a Number result.

           

          Regards

          Marc

          • 2. Re: Calculation getting Year Only
            comment

            MarcDolley wrote:

             

            Make sure both calculations are set to return a Number result.

             

            Ahm... the second calculation should be set to return Text.

            • 3. Re: Calculation getting Year Only
              MarcDolley

              The OP said "in number". I assume that meant they require a numerical value.

               

              Marc

              • 4. Re: Calculation getting Year Only
                comment

                Last two digits of 2001 is not a number.

                • 5. Re: Calculation getting Year Only
                  louie23

                  Thanks MarcDolley!!!!!

                  • 6. Re: Calculation getting Year Only
                    BruceHerbach

                    Michael,

                     

                    FileMaker will automaticly treat this a number.  Try this in the dataviewer.  right("2001";2 ) + 1

                     

                    The result is 2. 

                     

                    Bruce

                    • 7. Re: Calculation getting Year Only
                      comment

                      Bruce Herbach wrote:

                       

                      FileMaker will automaticly treat this a number.  Try this in the dataviewer.  right("2001";2 ) + 1

                       

                      You could have just as well said:

                       

                      FileMaker will automaticly treat this as text.  Try this in the data viewer: Right ( "2001" ; 2 ) & 1

                       

                      The result is "011".

                       

                       

                      In fact, both examples are irrelevant to the question.

                      • 8. Re: Calculation getting Year Only
                        raybaudi

                        Year(Get(CurrentDate)) is a valid answer but nevertheless incomplete if that calculation will be stored.

                        • 9. Re: Calculation getting Year Only

                          You are correct Bruce but you can add numbers in text fields also and that does not make them number. 

                           

                          The point made by Michael that 01 is not number is quite valid ... If you make it number and it is updated it would drop the leading zero.  These types of nuances can bite you and data type can be critical to understand.  If improperly utilized, Louie could end up with VERY old person born in year 201.

                          • 10. Re: Calculation getting Year Only
                            BruceHerbach

                            LaRetta,

                             

                            I agree.  I guess the real question is what was the  intent of the original question.  He did ask for numeric values.

                             

                            FileMaker has provided GetAs functions that make it easy to be explicit about these things and change the type.  Sometimes FileMaker takes things like this and initially make it very easy to do something like add a number to a text value and increment it numericly.  This then leads you into a minor issue down the road.

                             

                            Bruce

                            • 11. Re: Calculation getting Year Only
                              MarcDolley

                              Well, this thread went completely off the rails didn't it?

                              The OP asked two simple questions and didn't include any context. I'm pretty sure that if louie23 found that the answers offered by me didn't provide the correct results in the context in which they were being used, he or she would have asked for more information.

                               

                              Instead, the thread descended into arguments based on assumptions about context. All of the answers and arguments offered are completely correct, but I was quite happy to wait for louie23 to ask more questions instead of making assumptions and confusing the situation. For all we know, louie23 may require the year of the current date in a script step, making storage irrelavent or the year of birth to determine an odd or even 'number' for a numerology database. There is no way to tell from the original post.

                               

                              So, louie23, if you need more info about the calculations, please feel free to contact me privately.

                               

                              Regards

                              Marc

                              • 12. Re: Calculation getting Year Only
                                comment

                                MarcDolley wrote:

                                 

                                Instead, the thread descended into arguments based on assumptions about context. All of the answers and arguments offered are completely correct, but I was quite happy to wait for louie23 to ask more questions instead of making assumptions and confusing the situation. For all we know, louie23 may require the year of the current date in a script step, making storage irrelavent or the year of birth to determine an odd or even 'number' for a numerology database.

                                 

                                For all we know, louie23's English may not be perfect. To me, the only things that's clear without a doubt is that the result of the Right() function is text. Your recommendation to convert it into number was IMHO unwarranted.

                                 

                                Also, this is a public forum and the advice may apply to others that read the thread. I doubt anyone would ask for the "last two digits" and expect the leading zero to be excluded.

                                • 13. Re: Calculation getting Year Only

                                  Marc

                                   

                                  WOW.  I didn't see arguing anywhere nor did I feel a bit of negative spirit on this thread!   Where did that come from!!??

                                   

                                  If we think of something which might catch the person off guard or hurt them we speak up - we do NOT wait for them to experience the problem and then come back and ask why it broke!  If someone creates a number field to hold a zip code or writes GetAsNumber(phone) we SPEAK UP for same reason ... it can silently drop leading zeros. 

                                   

                                  Why is offering a caution about the data-type seen so negatively by you?  I doubt if anyone thought you were neglectful not to think of it.  We can't think of everything and we all make mistakes no matter how hard we try so we HOPE others speak up, filling in gaps of understanding, even correcting quotes, LOL.  That is why it is called a forum ... I was actually enjoying this thread and I like Bruce and Michael - I just don't know you or Louie yet.

                                   

                                  Not only might Louie appreciate the information beforehand but there are others who use these threads as well and that kind of information needs to be shared and discussed.  Even if someone on this thread DID disagree it was in no means disrespectful or argumentative; that is, until your post.        Contact you privately ... good grief ...

                                  • 14. Re: Calculation getting Year Only

                                    Bruce Herbach wrote:

                                     

                                    FileMaker has provided GetAs functions that make it easy to be explicit about these things and change the type.  Sometimes FileMaker takes things like this and initially make it very easy to do something like add a number to a text value and increment it numericly.  This then leads you into a minor issue down the road.

                                     

                                    Indeed!  FM is a bit odd in some respects (okay, many respects, LOL).  Allowing numeric operations in text fields (no I don't) and allowing text in number fields (no I don't)  which displays oddly in the index and makes searching text hit-or-miss.   It is best to respect the data types first and then use GetAs() when needed.  One of the biggest gotchas is text dates (as you know).  Probably five times a day, I see cautions (rightfully) being given because someone is creating a text date instead of using date functions.  :^)

                                    1 2 Previous Next