Why do I get an parse error in the first line? Please help. Thanks in advance.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • silvergost
    New Member
    • Oct 2009
    • 3

    Why do I get an parse error in the first line? Please help. Thanks in advance.

    Code:
    <?php
    
    int DMYToExcelSerialDate(int nDay, int nMonth, int nYear)
    {
        // Excel/Lotus 123 have a bug with 29-02-1900. 1900 is not a
        // leap year, but Excel/Lotus 123 think it is...
        if (nDay == 29 && nMonth == 02 && nYear==1900)
            return 60;
    
        // DMY to Modified Julian calculatie with an extra substraction of 2415019.
        long nSerialDate =
                int(( 1461 * ( nYear + 4800 + int(( nMonth - 14 ) / 12) ) ) / 4) +
                int(( 367 * ( nMonth - 2 - 12 * ( ( nMonth - 14 ) / 12 ) ) ) / 12) -
                int(( 3 * ( int(( nYear + 4900 + int(( nMonth - 14 ) / 12) ) / 100) ) ) / 4) +
                nDay - 2415019 - 32075;
    
        if (nSerialDate < 60)
        {
            // Because of the 29-02-1900 bug, any serial date
            // under 60 is one off... Compensate.
            nSerialDate--;
        }
    
        return (int)nSerialDate;
    }
    
    
    print (nSerialDate);
    
    ?>
    Last edited by Markus; Oct 11 '09, 10:31 AM. Reason: Added [code] tags...
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Because that is not PHP code. PHP is not a strongly type language, ergo variables and functions do not need (cannot have) their types declared.

    Consider the following:

    Code:
    // valid way of declaring a function - notice the 'function' keyword.
    function my_function($param1, $param2) {}
    // invalid way of declaring a function - lacks the 'function' keyword and also specifies return type of function
    int my_function($param1, $param2) {}
    // also invalid, same as above, but also specifies type of parameters (please see next example also)
    int my_function(int $param1, int $param2) {}
    // you can 'type-hint' certain values for your parameters, such as 'array'
    // and classes
    function my_function(array $param1, my_class $param2) {}
    
    // correct way to define a variable
    $my_variable = 1;
    // incorrect
    int $my_variable = 1;
    Hope this helps,
    Mark.

    P.S. Welcome to the forum!
    P.P.S Please use code tags when posting code to the forum. That can be done as [code] your code here [/code].

    Comment

    • silvergost
      New Member
      • Oct 2009
      • 3

      #3
      Thanks for the reply Mark,
      I simply just wanted to convert a Date YYYYMMDD to an Excel serial date, using .php code. I'm not having much success as I am new to .php.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by silvergost
        Thanks for the reply Mark,
        I simply just wanted to convert a Date YYYYMMDD to an Excel serial date, using .php code. I'm not having much success as I am new to .php.
        Read some tutorials, and you'll be able to do it yourself based on the above algorithm.

        Comment

        • silvergost
          New Member
          • Oct 2009
          • 3

          #5
          Thanks for the confidence in me. At least I can gather from your reply that what I whant to do is possible.

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by silvergost
            Thanks for the confidence in me. At least I can gather from your reply that what I whant to do is possible.
            Sure it is - all you're really doing is some math, which PHP handles just like any other language. I would give you a head start, but I have to run out.

            Mark.

            Comment

            Working...