Why do I get an parse error in the first line? Please help. Thanks in advance. | Newbie | | Join Date: Oct 2009 Location: Benoni, South Africa
Posts: 3
| | - <?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);
-
-
?>
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,947
| | | re: Why do I get an parse error in the first line? Please help. Thanks in advance.
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: -
// 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].
| | Newbie | | Join Date: Oct 2009 Location: Benoni, South Africa
Posts: 3
| | | re: Why do I get an parse error in the first line? Please help. Thanks in advance.
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.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,947
| | | re: Why do I get an parse error in the first line? Please help. Thanks in advance. Quote:
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.
| | Newbie | | Join Date: Oct 2009 Location: Benoni, South Africa
Posts: 3
| | | re: Why do I get an parse error in the first line? Please help. Thanks in advance.
Thanks for the confidence in me. At least I can gather from your reply that what I whant to do is possible.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,947
| | | re: Why do I get an parse error in the first line? Please help. Thanks in advance. Quote:
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.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|