1 2 Previous Next 16 Replies Latest reply on Aug 22, 2014 1:18 AM by Nehme

    Get (CurrentDate) from the net

    Nehme

      Hello,

       

      Usually, the Get (CurrentDate) function gets the date from the computer.

      Is there any way to get the current date from the internet instead (so that the user cannot change the date by changing the computer's date)?

        • 1. Re: Get (CurrentDate) from the net
          Mike_Mitchell

          If you're operating using FileMaker Server, you can use the Get ( CurrentHostTimestamp ) function. This will return the current timestamp held on the server.

          • 2. Re: Get (CurrentDate) from the net
            Nehme

            Excuse me for not mentioning that.

            But I am using Filemaker Pro 13 Advanced.

             

            And I am assuming that the user has an internet connection.

            • 3. Re: Get (CurrentDate) from the net
              BruceHerbach

              If you are hosted on FMS 13 you can use perform script on server to get the

              servers current date.

               

              The user won't be able to change that. To do this,  creat a simple script

              that puts the date in a variable and exits with the variable as the

              argument.  Then use get(script result) to get the date in your current

              script.

               

              HTH

              Bruce

               

              Sent from my mobile device... Please excuse typos.

              • 4. Re: Get (CurrentDate) from the net
                erolst

                You could use Insert from URL[] with a known webpage that features the current date, and parse it out.

                • 5. Re: Get (CurrentDate) from the net
                  Nehme

                  Thank you for your help

                   

                  1- The problem is that I am not even hosted on FMS.

                   

                  2- How can we capture the date from a website. Is there any specific script or is it a simple URL insertion.

                  • 6. Re: Get (CurrentDate) from the net
                    Mike_Mitchell

                    You can use a website such as http://todays-date.net. As erolst suggests, use Insert From URL to push the contents of the page into a text field and then parse out the date. For example, this particular web site has a particular tag to identify the date:

                     

                         [p id="date"]

                     

                    (where the normal "<" and ">" delimiters replace the "[" and "]" I've used)

                     

                    Use text parsing functions like PatternCount, Left, and Middle to extract the data between that tag and the closing [/p] tag to get the date.

                     

                    HTH

                     

                    Mike

                    • 7. Re: Get (CurrentDate) from the net
                      erolst


                      Mike_Mitchell wrote:

                      Use text parsing functions like PatternCount, Left, and Middle to extract the data between that tag and the closing [/p] tag to get the date

                       

                      As an example:

                       

                      Insert from URL [ YourTable::yourField ; http://todays-date.net ]

                      Set Field ( YourTable::someDateField ; seeCalculationBelow ]

                       

                      Let ( [

                        html = YourTable::yourField;

                       

                        startTag = " <p id=\"date\">" ;

                        pos1 = Position ( html ; startTag ; 1 ; 1 ) + Length ( startTag ) ;

                        pos2 = Position ( html ; "</p>" ; pos1 ; 1 ) ;

                        dateString = Middle ( html ; pos1 ; pos2 - pos1 ) ;

                       

                        dateList = Substitute ( dateString ; ", " ; ¶ ) ;

                        y = GetValue ( dateList ; 3 ) ;

                        md = GetValue ( dateList ; 2 ) ;

                        mstring = LeftWords ( md ; 1 ) ;

                        d = RightWords ( md ; 2 ) ;

                        mList = "January¶February¶March¶April¶May¶June¶July¶August¶September¶October¶November¶December" ;

                        m = ValueCount ( Left ( mList ; Position ( mList & ¶ ; mstring & ¶ ; 1 ; 1 ) ) )

                        ] ;

                        Date ( m ; d ; y )

                      )

                       

                      Note that you can and should factor out some of the logic as Custom Functions – e.g. ItemIndexInList(), ListOfEnglishMonthNames() – since they're useful for a number of applications.

                      • 8. Re: Get (CurrentDate) from the net
                        TomHays

                        If you have access to your own website, you can create a simple page that shows the date in a way that is very easy to parse in FileMaker.  Beyond making it easy to parse, you can also be sure that the website won't change the structure of its source code and break your parsing calculation.

                         

                        You will need to have a server-side scripting language such as PHP on your web server so that the date can be calculated and then presented in the HTML source that is delivered when you make an Insert From URL request.  (If the date is calculated client-side via JavaScript, your source code will just show the JavaScript code and not the results of the JavaScript calculation.)

                         

                        Here is a simple PHP script that you can save as "today.php" on your web server.

                        The entire result of Insert From URL will be a date expressed as YYY-MM-DD which you can parse using Middle() for the pieces and reassemble with Date().

                         

                        <?php

                        date_default_timezone_set("America/New_York");

                        echo date("Y-m-d");

                        ?>

                         

                        You might use

                        date_default_timezone_set("Etc/UTC");

                        if you would prefer to use Universal Coordinated Time for your time zone.

                         

                        If you want an even simpler date for parsing in FileMaker, you can do something like the following which will put YYYY, MM, and DD onto three separate lines which you can parse using GetValue() for each line.

                        <?php

                        date_default_timezone_set("America/New_York");

                        echo date("Y\n");

                        echo date("m\n");

                        echo date("d\n");

                        ?>

                         

                        -Tom

                        • 9. Re: Get (CurrentDate) from the net
                          dvaklyes

                          This site: http://www.timeapi.org/ gives results in a much simpler format. For example, http://www.timeapi.org/utc/now returns the current UTC time as 2014-08-17T04:29:04+01:00

                           

                          Makes parsing the result much easier. You can also add formatting code to the URL to get only the date in the format you want.

                           

                          Search for "time api" online to get other sites.

                           

                          Dave Vaklyes

                          • 10. Re: Get (CurrentDate) from the net
                            erolst

                            David W Vaklyes wrote:

                            This site: http://www.timeapi.org/ gives results in a much simpler format.

                            I knew there had to be one …

                            • 11. Re: Get (CurrentDate) from the net
                              Mike_Mitchell

                              Good show!  

                              • 12. Re: Get (CurrentDate) from the net
                                taylorsharpe

                                Sometimes I like to have a Date and time displayed on my layouts with the time continually incrementing every second.  To do this, I create a small rectangular web portal and put this in it:

                                 

                                "data:text/html,

                                <head>

                                <script language='javascript' type='text/javascript'>

                                function timeStamp() {

                                document.getElementById('TS').innerHTML=(new Date).toLocaleString();

                                setTimeout('timeStamp()', 1000);

                                }

                                </script>

                                </head>

                                <body style='background-color: FFFFFF'; onload='timeStamp()'>

                                <div id='TS' style='color: 0E2A52; text-align:center; font:bold 10px Arial, sans-serif;'></div>

                                </body>"

                                 

                                 

                                 

                                 

                                This does not get the time from the internet like you asked, but sometimes people are just wanting to see time being updated within a layout. 

                                • 13. Re: Get (CurrentDate) from the net
                                  Nehme

                                  Thank you all for your help.

                                  You were really very helpful.

                                  Thanks again

                                  • 14. Re: Get (CurrentDate) from the net
                                    Nehme

                                    This is a very nice idea: to take the date from your own site.

                                     

                                    But in my site, I am using the html code.

                                    But the problem is that, among all the "Current Date" codes that I wrote and I searched on the net, all those are giving the date of my computer (If I change the date on my computer, they will also change the date on my website).

                                     

                                    Do you have an html code that could take the date from the net instead of taking it from my computer.

                                     

                                    Thanks again for your help.

                                    1 2 Previous Next