For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1000 lines
27 KiB

  1. # Calculation Engine - Formula Function Reference
  2. ## Function Reference
  3. ### Date and Time Functions
  4. Excel provides a number of functions for the manipulation of dates and times, and calculations based on date/time values. it is worth spending some time reading the section titled "Date and Time Values" on passing date parameters and returning date values to understand how PHPExcel reconciles the differences between dates and times in Excel and in PHP.
  5. #### DATE
  6. The DATE function returns an Excel timestamp or a PHP timestamp or date object representing the date that is referenced by the parameters.
  7. ##### Syntax
  8. ```
  9. DATE(year, month, day)
  10. ```
  11. ##### Parameters
  12. **year** The year number.
  13. If this value is between 0 (zero) and 1899 inclusive (for the Windows 1900 calendar), or between 4 and 1903 inclusive (for the Mac 1904), then PHPExcel adds it to the Calendar base year, so a value of 108 will interpret the year as 2008 when using the Windows 1900 calendar, or 2012 when using the Mac 1904 calendar.
  14. **month** The month number.
  15. If this value is greater than 12, the DATE function adds that number of months to the first month in the year specified. For example, DATE(2008,14,2) returns a value representing February 2, 2009.
  16. If the value of __month__ is less than 1, then that value will be adjusted by -1, and that will then be subtracted from the first month of the year specified. For example, DATE(2008,0,2) returns a value representing December 2, 2007; while DATE(2008,-1,2) returns a value representing November 2, 2007.
  17. **day** The day number.
  18. If this value is greater than the number of days in the month (and year) specified, the DATE function adds that number of days to the first day in the month. For example, DATE(2008,1,35) returns a value representing February 4, 2008.
  19. If the value of __day__ is less than 1, then that value will be adjusted by -1, and that will then be subtracted from the first month of the year specified. For example, DATE(2008,3,0) returns a value representing February 29, 2008; while DATE(2008,3,-2) returns a value representing February 27, 2008.
  20. ##### Return Value
  21. **mixed** A date/time stamp that corresponds to the given date.
  22. This could be a PHP timestamp value (integer), a PHP date/time object, or an Excel timestamp value (real), depending on the value of PHPExcel_Calculation_Functions::getReturnDateType().
  23. ##### Examples
  24. ```php
  25. $worksheet->setCellValue('A1', 'Year')
  26. ->setCellValue('A2', 'Month')
  27. ->setCellValue('A3', 'Day');
  28. $worksheet->setCellValue('B1', 2008)
  29. ->setCellValue('B2', 12)
  30. ->setCellValue('B3', 31);
  31. $worksheet->setCellValue('D1', '=DATE(B1,B2,B3)');
  32. $retVal = $worksheet->getCell('D1')->getCalculatedValue();
  33. // $retVal = 1230681600
  34. ```
  35. ```php
  36. // We're going to be calling the same cell calculation multiple times,
  37. // and expecting different return values, so disable calculation cacheing
  38. PHPExcel_Calculation::getInstance()->setCalculationCacheEnabled(FALSE);
  39. $saveFormat = PHPExcel_Calculation_Functions::getReturnDateType();
  40. PHPExcel_Calculation_Functions::setReturnDateType(
  41. PHPExcel_Calculation_Functions::RETURNDATE_EXCEL
  42. );
  43. $retVal = call_user_func_array(
  44. array('PHPExcel_Calculation_Functions', 'DATE'),
  45. array(2008, 12, 31)
  46. );
  47. // $retVal = 39813.0
  48. PHPExcel_Calculation_Functions::setReturnDateType(
  49. PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC
  50. );
  51. $retVal = call_user_func_array(
  52. array('PHPExcel_Calculation_Functions', 'DATE'),
  53. array(2008, 12, 31)
  54. );
  55. // $retVal = 1230681600
  56. PHPExcel_Calculation_Functions::setReturnDateType($saveFormat);
  57. ```
  58. ##### Notes
  59. There are no additional notes on this function
  60. #### DATEDIF
  61. The DATEDIF function computes the difference between two dates in a variety of different intervals, such number of years, months, or days.
  62. ##### Syntax
  63. ```
  64. DATEDIF(date1, date2 [, unit])
  65. ```
  66. ##### Parameters
  67. **date1** First Date.
  68. An Excel date value, PHP date timestamp, PHP date object, or a date represented as a string.
  69. **date2** Second Date.
  70. An Excel date value, PHP date timestamp, PHP date object, or a date represented as a string.
  71. **unit** The interval type to use for the calculation
  72. This is a string, comprising one of the values listed below:
  73. Unit | Meaning | Description
  74. -----|---------------------------------|--------------------------------
  75. m | Months | Complete calendar months between the dates.
  76. d | Days | Number of days between the dates.
  77. y | Years | Complete calendar years between the dates.
  78. ym | Months Excluding Years | Complete calendar months between the dates as if they were of the same year.
  79. yd | Days Excluding Years | Complete calendar days between the dates as if they were of the same year.
  80. md | Days Excluding Years And Months | Complete calendar days between the dates as if they were of the same month and same year.
  81. The unit value is not case sensitive, and defaults to "d".
  82. ##### Return Value
  83. **integer** An integer value that reflects the difference between the two dates.
  84. This could be the number of full days, months or years between the two dates, depending on the interval unit value passed into the function as the third parameter.
  85. ##### Examples
  86. ```php
  87. $worksheet->setCellValue('A1', 'Year')
  88. ->setCellValue('A2', 'Month')
  89. ->setCellValue('A3', 'Day');
  90. $worksheet->setCellValue('B1', 2001)
  91. ->setCellValue('C1', 2009)
  92. ->setCellValue('B2', 7)
  93. ->setCellValue('C2', 12)
  94. ->setCellValue('B3', 1)
  95. ->setCellValue('C3', 31);
  96. $worksheet->setCellValue('D1', '=DATEDIF(DATE(B1,B2,B3),DATE(C1,C2,C3),"d")')
  97. ->setCellValue('D2', '=DATEDIF(DATE(B1,B2,B3),DATE(C1,C2,C3),"m")')
  98. ->setCellValue('D3', '=DATEDIF(DATE(B1,B2,B3),DATE(C1,C2,C3),"y")')
  99. ->setCellValue('D4', '=DATEDIF(DATE(B1,B2,B3),DATE(C1,C2,C3),"ym")')
  100. ->setCellValue('D5', '=DATEDIF(DATE(B1,B2,B3),DATE(C1,C2,C3),"yd")')
  101. ->setCellValue('D6', '=DATEDIF(DATE(B1,B2,B3),DATE(C1,C2,C3),"md")');
  102. $retVal = $worksheet->getCell('D1')->getCalculatedValue();
  103. // $retVal = 3105
  104. $retVal = $worksheet->getCell('D2')->getCalculatedValue();
  105. // $retVal = 101
  106. $retVal = $worksheet->getCell('D3')->getCalculatedValue();
  107. // $retVal = 8
  108. $retVal = $worksheet->getCell('D4')->getCalculatedValue();
  109. // $retVal = 5
  110. $retVal = $worksheet->getCell('D5')->getCalculatedValue();
  111. // $retVal = 183
  112. $retVal = $worksheet->getCell('D6')->getCalculatedValue();
  113. // $retVal = 30
  114. ```
  115. ```php
  116. $date1 = 1193317015; // PHP timestamp for 25-Oct-2007
  117. $date2 = 1449579415; // PHP timestamp for 8-Dec-2015
  118. $retVal = call_user_func_array(
  119. array('PHPExcel_Calculation_Functions', 'DATEDIF'),
  120. array($date1, $date2, 'd')
  121. );
  122. // $retVal = 2966
  123. $retVal = call_user_func_array(
  124. array('PHPExcel_Calculation_Functions', 'DATEDIF'),
  125. array($date1, $date2, 'm')
  126. );
  127. // $retVal = 97
  128. $retVal = call_user_func_array(
  129. array('PHPExcel_Calculation_Functions', 'DATEDIF'),
  130. array($date1, $date2, 'y')
  131. );
  132. // $retVal = 8
  133. $retVal = call_user_func_array(
  134. array('PHPExcel_Calculation_Functions', 'DATEDIF'),
  135. array($date1, $date2, 'ym')
  136. );
  137. // $retVal = 1
  138. $retVal = call_user_func_array(
  139. array('PHPExcel_Calculation_Functions', 'DATEDIF'),
  140. array($date1, $date2, 'yd')
  141. );
  142. // $retVal = 44
  143. $retVal = call_user_func_array(
  144. array('PHPExcel_Calculation_Functions', 'DATEDIF'),
  145. array($date1, $date2, 'md')
  146. );
  147. // $retVal = 13
  148. ```
  149. ##### Notes
  150. If Date1 is later than Date2, DATEDIF will return a #NUM! error.
  151. #### DATEVALUE
  152. The DATEVALUE function returns the date represented by a date formatted as a text string. Use DATEVALUE to convert a date represented by text to a serial number.
  153. ##### Syntax
  154. ```
  155. DATEVALUE(dateString)
  156. ```
  157. ##### Parameters
  158. **date** Date String.
  159. A string, representing a date value.
  160. ##### Return Value
  161. **mixed** A date/time stamp that corresponds to the given date.
  162. This could be a PHP timestamp value (integer), a PHP date/time object, or an Excel timestamp value (real), depending on the value of PHPExcel_Calculation_Functions::getReturnDateType().
  163. ##### Examples
  164. ```php
  165. $worksheet->setCellValue('A1', 'Date String');
  166. ->setCellValue('A2', '31-Dec-2008')
  167. ->setCellValue('A3', '31/12/2008')
  168. ->setCellValue('A4', '12-31-2008');
  169. $worksheet->setCellValue('B2', '=DATEVALUE(A2)')
  170. ->setCellValue('B3', '=DATEVALUE(A3)')
  171. ->setCellValue('B4', '=DATEVALUE(A4)');
  172. PHPExcel_Calculation_Functions::setReturnDateType(
  173. PHPExcel_Calculation_Functions::RETURNDATE_EXCEL
  174. );
  175. $retVal = $worksheet->getCell('B2')->getCalculatedValue();
  176. $retVal = $worksheet->getCell('B3')->getCalculatedValue();
  177. $retVal = $worksheet->getCell('B4')->getCalculatedValue();
  178. // $retVal = 39813.0 for all cases
  179. ```
  180. ```php
  181. // We're going to be calling the same cell calculation multiple times,
  182. // and expecting different return values, so disable calculation cacheing
  183. PHPExcel_Calculation::getInstance()->setCalculationCacheEnabled(FALSE);
  184. $saveFormat = PHPExcel_Calculation_Functions::getReturnDateType();
  185. PHPExcel_Calculation_Functions::setReturnDateType(
  186. PHPExcel_Calculation_Functions::RETURNDATE_EXCEL
  187. );
  188. $retVal = call_user_func_array(
  189. array('PHPExcel_Calculation_Functions', 'DATEVALUE'),
  190. array('31-Dec-2008')
  191. );
  192. // $retVal = 39813.0
  193. PHPExcel_Calculation_Functions::setReturnDateType(
  194. PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC
  195. );
  196. $retVal = call_user_func_array(
  197. array('PHPExcel_Calculation_Functions', 'DATEVALUE'),
  198. array('31-Dec-2008')
  199. );
  200. // $retVal = 1230681600
  201. PHPExcel_Calculation_Functions::setReturnDateType($saveFormat);
  202. ```
  203. ##### Notes
  204. DATEVALUE uses the php date/time object implementation of strtotime() (which can handle a wider range of formats than the normal strtotime() function), and it is also called for any date parameter passed to other date functions (such as DATEDIF) when the parameter value is a string.
  205. __WARNING:-__ PHPExcel accepts a wider range of date formats than MS Excel, so it is entirely possible that Excel will return a #VALUE! error when passed a date string that it can’t interpret, while PHPExcel is able to translate that same string into a correct date value.
  206. Care should be taken in workbooks that use string formatted dates in calculations when writing to Excel5 or Excel2007.
  207. #### DAY
  208. The DAY function returns the day of a date. The day is given as an integer ranging from 1 to 31.
  209. ##### Syntax
  210. ```
  211. DAY(datetime)
  212. ```
  213. ##### Parameters
  214. **datetime** Date.
  215. An Excel date value, PHP date timestamp, PHP date object, or a date represented as a string.
  216. ##### Return Value
  217. **integer** An integer value that reflects the day of the month.
  218. This is an integer ranging from 1 to 31.
  219. ##### Examples
  220. ```php
  221. $worksheet->setCellValue('A1', 'Date String')
  222. ->setCellValue('A2', '31-Dec-2008')
  223. ->setCellValue('A3', '14-Feb-2008');
  224. $worksheet->setCellValue('B2', '=DAY(A2)')
  225. ->setCellValue('B3', '=DAY(A3)');
  226. $retVal = $worksheet->getCell('B2')->getCalculatedValue();
  227. // $retVal = 31
  228. $retVal = $worksheet->getCell('B3')->getCalculatedValue();
  229. // $retVal = 14
  230. ```
  231. ```php
  232. $retVal = call_user_func_array(
  233. array('PHPExcel_Calculation_Functions', 'DAYOFMONTH'),
  234. array('25-Dec-2008')
  235. );
  236. // $retVal = 25
  237. ```
  238. ##### Notes
  239. Note that the PHPExcel function is PHPExcel_Calculation_Functions::DAYOFMONTH() when the method is called statically.
  240. #### DAYS360
  241. The DAYS360 function computes the difference between two dates based on a 360 day year (12 equal periods of 30 days each) used by some accounting systems.
  242. ##### Syntax
  243. ```
  244. DAYS360(date1, date2 [, method])
  245. ```
  246. #### Parameters
  247. **date1** First Date.
  248. An Excel date value, PHP date timestamp, PHP date object, or a date represented as a string.
  249. **date2** Second Date.
  250. An Excel date value, PHP date timestamp, PHP date object, or a date represented as a string.
  251. **method** A boolean flag (TRUE or FALSE)
  252. This is a flag that determines which method to use in the calculation, based on the values listed below:
  253. method | Description
  254. -------|------------
  255. FALSE | U.S. (NASD) method. If the starting date is the last day of a month, it becomes equal to the 30th of the same month. If the ending date is the last day of a month and the starting date is earlier than the 30th of a month, the ending date becomes equal to the 1st of the next month; otherwise the ending date becomes equal to the 30th of the same month.
  256. TRUE | European method. Starting dates and ending dates that occur on the 31st of a month become equal to the 30th of the same month.
  257. The method value defaults to FALSE.
  258. ##### Return Value
  259. **integer** An integer value that reflects the difference between the two dates.
  260. This is the number of full days between the two dates, based on a 360 day year.
  261. ##### Examples
  262. ```php
  263. $worksheet->setCellValue('B1', 'Start Date')
  264. ->setCellValue('C1', 'End Date')
  265. ->setCellValue('A2', 'Year')
  266. ->setCellValue('A3', 'Month')
  267. ->setCellValue('A4', 'Day');
  268. $worksheet->setCellValue('B2', 2003)
  269. ->setCellValue('B3', 2)
  270. ->setCellValue('B4', 3);
  271. $worksheet->setCellValue('C2', 2007)
  272. ->setCellValue('C3', 5)
  273. ->setCellValue('C4', 31);
  274. $worksheet->setCellValue('E2', '=DAYS360(DATE(B2,B3,B4),DATE(C2,C3,C4))')
  275. ->setCellValue('E4', '=DAYS360(DATE(B2,B3,B4),DATE(C2,C3,C4),FALSE)');
  276. $retVal = $worksheet->getCell('E2')->getCalculatedValue();
  277. // $retVal = 1558
  278. $retVal = $worksheet->getCell('E4')->getCalculatedValue();
  279. // $retVal = 1557
  280. ```
  281. ```php
  282. $date1 = 37655.0; // Excel timestamp for 25-Oct-2007
  283. $date2 = 39233.0; // Excel timestamp for 8-Dec-2015
  284. $retVal = call_user_func_array(
  285. array('PHPExcel_Calculation_Functions', 'DAYS360'),
  286. array($date1, $date2)
  287. );
  288. // $retVal = 1558
  289. $retVal = call_user_func_array(
  290. array('PHPExcel_Calculation_Functions', 'DAYS360'),
  291. array($date1, $date2, TRUE)
  292. );
  293. // $retVal = 1557
  294. ```
  295. ##### Notes
  296. __WARNING:-__ This function does not currently work with the Excel5 Writer when a PHP Boolean is used for the third (optional) parameter (as shown in the example above), and the writer will generate and error. It will work if a numeric 0 or 1 is used for the method parameter; or if the Excel TRUE() and FALSE() functions are used instead.
  297. #### EDATE
  298. The EDATE function returns an Excel timestamp or a PHP timestamp or date object representing the date that is the indicated number of months before or after a specified date (the start_date). Use EDATE to calculate maturity dates or due dates that fall on the same day of the month as the date of issue.
  299. ##### Syntax
  300. ```
  301. EDATE(baseDate, months)
  302. ```
  303. ##### Parameters
  304. **baseDate** Start Date.
  305. An Excel date value, PHP date timestamp, PHP date object, or a date represented as a string.
  306. **months** Number of months to add.
  307. An integer value indicating the number of months before or after baseDate. A positive value for months yields a future date; a negative value yields a past date.
  308. ##### Return Value
  309. **mixed** A date/time stamp that corresponds to the basedate + months.
  310. This could be a PHP timestamp value (integer), a PHP date/time object, or an Excel timestamp value (real), depending on the value of PHPExcel_Calculation_Functions::getReturnDateType().
  311. ##### Examples
  312. ```php
  313. $worksheet->setCellValue('A1', 'Date String')
  314. ->setCellValue('A2', '1-Jan-2008')
  315. ->setCellValue('A3', '29-Feb-2008');
  316. $worksheet->setCellValue('B2', '=EDATE(A2,5)')
  317. ->setCellValue('B3', '=EDATE(A3,-12)');
  318. PHPExcel_Calculation_Functions::setReturnDateType(
  319. PHPExcel_Calculation_Functions::RETURNDATE_EXCEL
  320. );
  321. $retVal = $worksheet->getCell('B2')->getCalculatedValue();
  322. // $retVal = 39600.0 (1-Jun-2008)
  323. $retVal = $worksheet->getCell('B3')->getCalculatedValue();
  324. // $retVal = 39141.0 (28-Feb-2007)
  325. ```
  326. ```php
  327. PHPExcel_Calculation_Functions::setReturnDateType(
  328. PHPExcel_Calculation_Functions::RETURNDATE_EXCEL
  329. );
  330. $retVal = call_user_func_array(
  331. array('PHPExcel_Calculation_Functions', 'EDATE'),
  332. array('31-Oct-2008',25)
  333. );
  334. // $retVal = 40512.0 (30-Nov-2010)
  335. ```
  336. ###### Notes
  337. __WARNING:-__ This function is currently not supported by the Excel5 Writer because it is not a standard function within Excel 5, but an add-in from the Analysis ToolPak.
  338. #### EOMONTH
  339. The EOMONTH function returns an Excel timestamp or a PHP timestamp or date object representing the date of the last day of the month that is the indicated number of months before or after a specified date (the start_date). Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month.
  340. ##### Syntax
  341. ```
  342. EOMONTH(baseDate, months)
  343. ```
  344. ##### Parameters
  345. **baseDate** Start Date.
  346. An Excel date value, PHP date timestamp, PHP date object, or a date represented as a string.
  347. **months** Number of months to add.
  348. An integer value indicating the number of months before or after baseDate. A positive value for months yields a future date; a negative value yields a past date.
  349. ##### Return Value
  350. **mixed** A date/time stamp that corresponds to the last day of basedate + months.
  351. This could be a PHP timestamp value (integer), a PHP date/time object, or an Excel timestamp value (real), depending on the value of PHPExcel_Calculation_Functions::getReturnDateType().
  352. ##### Examples
  353. ```php
  354. $worksheet->setCellValue('A1', 'Date String')
  355. ->setCellValue('A2', '1-Jan-2000')
  356. ->setCellValue('A3', '14-Feb-2009');
  357. $worksheet->setCellValue('B2', '=EOMONTH(A2,5)')
  358. ->setCellValue('B3', '=EOMONTH(A3,-12)');
  359. PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL);
  360. $retVal = $worksheet->getCell('B2')->getCalculatedValue();
  361. // $retVal = 39629.0 (30-Jun-2008)
  362. $retVal = $worksheet->getCell('B3')->getCalculatedValue();
  363. // $retVal = 39507.0 (29-Feb-2008)
  364. ```
  365. ```php
  366. PHPExcel_Calculation_Functions::setReturnDateType(
  367. PHPExcel_Calculation_Functions::RETURNDATE_EXCEL
  368. );
  369. $retVal = call_user_func_array(
  370. array('PHPExcel_Calculation_Functions', 'EOMONTH'),
  371. array('31-Oct-2008',13)
  372. );
  373. // $retVal = 40147.0 (30-Nov-2010)
  374. ```
  375. ##### Notes
  376. __WARNING:-__ This function is currently not supported by the Excel5 Writer because it is not a standard function within Excel 5, but an add-in from the Analysis ToolPak.
  377. #### HOUR
  378. The HOUR function returns the hour of a time value. The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.).
  379. ##### Syntax
  380. ```
  381. HOUR(datetime)
  382. ```
  383. ##### Parameters
  384. **datetime** Time.
  385. An Excel date/time value, PHP date timestamp, PHP date object, or a date/time represented as a string.
  386. ##### Return Value
  387. **integer** An integer value that reflects the hour of the day.
  388. This is an integer ranging from 0 to 23.
  389. ##### Examples
  390. ```php
  391. $worksheet->setCellValue('A1', 'Time String')
  392. ->setCellValue('A2', '31-Dec-2008 17:30')
  393. ->setCellValue('A3', '14-Feb-2008 4:20 AM')
  394. ->setCellValue('A4', '14-Feb-2008 4:20 PM');
  395. $worksheet->setCellValue('B2', '=HOUR(A2)')
  396. ->setCellValue('B3', '=HOUR(A3)')
  397. ->setCellValue('B4', '=HOUR(A4)');
  398. $retVal = $worksheet->getCell('B2')->getCalculatedValue();
  399. // $retVal = 17
  400. $retVal = $worksheet->getCell('B3')->getCalculatedValue();
  401. // $retVal = 4
  402. $retVal = $worksheet->getCell('B4')->getCalculatedValue();
  403. // $retVal = 16
  404. ```
  405. ```php
  406. $retVal = call_user_func_array(
  407. array('PHPExcel_Calculation_Functions', 'HOUROFDAY'),
  408. array('09:30')
  409. );
  410. // $retVal = 9
  411. ```
  412. ##### Notes
  413. Note that the PHPExcel function is PHPExcel_Calculation_Functions::HOUROFDAY() when the method is called statically.
  414. #### MINUTE
  415. The MINUTE function returns the minutes of a time value. The minute is given as an integer, ranging from 0 to 59.
  416. ##### Syntax
  417. ```
  418. MINUTE(datetime)
  419. ```
  420. ##### Parameters
  421. **datetime** Time.
  422. An Excel date/time value, PHP date timestamp, PHP date object, or a date/time represented as a string.
  423. ##### Return Value
  424. **integer** An integer value that reflects the minutes within the hour.
  425. This is an integer ranging from 0 to 59.
  426. ##### Examples
  427. ```php
  428. $worksheet->setCellValue('A1', 'Time String')
  429. ->setCellValue('A2', '31-Dec-2008 17:30')
  430. ->setCellValue('A3', '14-Feb-2008 4:20 AM')
  431. ->setCellValue('A4', '14-Feb-2008 4:45 PM');
  432. $worksheet->setCellValue('B2', '=MINUTE(A2)')
  433. ->setCellValue('B3', '=MINUTE(A3)')
  434. ->setCellValue('B4', '=MINUTE(A4)');
  435. $retVal = $worksheet->getCell('B2')->getCalculatedValue();
  436. // $retVal = 30
  437. $retVal = $worksheet->getCell('B3')->getCalculatedValue();
  438. // $retVal = 20
  439. $retVal = $worksheet->getCell('B4')->getCalculatedValue();
  440. // $retVal = 45
  441. ```
  442. ```php
  443. $retVal = call_user_func_array(
  444. array('PHPExcel_Calculation_Functions', 'MINUTEOFHOUR'),
  445. array('09:30')
  446. );
  447. // $retVal = 30
  448. ```
  449. ##### Notes
  450. Note that the PHPExcel function is PHPExcel_Calculation_Functions::MINUTEOFHOUR() when the method is called statically.
  451. #### MONTH
  452. The MONTH function returns the month of a date. The month is given as an integer ranging from 1 to 12.
  453. ##### Syntax
  454. ```
  455. MONTH(datetime)
  456. ```
  457. ##### Parameters
  458. **datetime** Date.
  459. An Excel date value, PHP date timestamp, PHP date object, or a date represented as a string.
  460. ##### Return Value
  461. **integer** An integer value that reflects the month of the year.
  462. This is an integer ranging from 1 to 12.
  463. ##### Examples
  464. ```php
  465. $worksheet->setCellValue('A1', 'Date String');
  466. $worksheet->setCellValue('A2', '31-Dec-2008');
  467. $worksheet->setCellValue('A3', '14-Feb-2008');
  468. $worksheet->setCellValue('B2', '=MONTH(A2)');
  469. $worksheet->setCellValue('B3', '=MONTH(A3)');
  470. $retVal = $worksheet->getCell('B2')->getCalculatedValue();
  471. // $retVal = 12
  472. $retVal = $worksheet->getCell('B3')->getCalculatedValue();
  473. // $retVal = 2
  474. ```
  475. ```php
  476. $retVal = call_user_func_array(
  477. array('PHPExcel_Calculation_Functions', 'MONTHOFYEAR'),
  478. array('14-July-2008')
  479. );
  480. // $retVal = 7
  481. ```
  482. #### Notes
  483. Note that the PHPExcel function is PHPExcel_Calculation_Functions::MONTHOFYEAR() when the method is called statically.
  484. #### NETWORKDAYS
  485. The NETWORKDAYS function returns the number of whole working days between a *start date* and an *end date*. Working days exclude weekends and any dates identified in *holidays*. Use NETWORKDAYS to calculate employee benefits that accrue based on the number of days worked during a specific term.
  486. ##### Syntax
  487. ```
  488. NETWORKDAYS(startDate, endDate [, holidays])
  489. ```
  490. ##### Parameters
  491. **startDate** Start Date of the period.
  492. An Excel date value, PHP date timestamp, PHP date object, or a date represented as a string.
  493. **endDate** End Date of the period.
  494. An Excel date value, PHP date timestamp, PHP date object, or a date represented as a string.
  495. **holidays** Optional array of Holiday dates.
  496. An optional range of one or more dates to exclude from the working calendar, such as state and federal holidays and floating holidays.
  497. The list can be either a range of cells that contains the dates or an array constant of Excel date values, PHP date timestamps, PHP date objects, or dates represented as strings.
  498. ##### Return Value
  499. **integer** Number of working days.
  500. The number of working days between startDate and endDate.
  501. ##### Examples
  502. ```php
  503. ```
  504. ```php
  505. ```
  506. ##### Notes
  507. There are no additional notes on this function
  508. #### NOW
  509. The NOW function returns the current date and time.
  510. ##### Syntax
  511. ```
  512. NOW()
  513. ```
  514. ##### Parameters
  515. There are now parameters for the NOW() function.
  516. ##### Return Value
  517. **mixed** A date/time stamp that corresponds to the current date and time.
  518. This could be a PHP timestamp value (integer), a PHP date/time object, or an Excel timestamp value (real), depending on the value of PHPExcel_Calculation_Functions::getReturnDateType().
  519. ##### Examples
  520. ```php
  521. ```
  522. ```php
  523. ```
  524. ##### Notes
  525. Note that the PHPExcel function is PHPExcel_Calculation_Functions::DATETIMENOW() when the method is called statically.
  526. #### SECOND
  527. The SECOND function returns the seconds of a time value. The second is given as an integer, ranging from 0 to 59.
  528. ##### Syntax
  529. ```
  530. SECOND(datetime)
  531. ```
  532. ##### Parameters
  533. **datetime** Time.
  534. An Excel date/time value, PHP date timestamp, PHP date object, or a date/time represented as a string.
  535. ##### Return Value
  536. **integer** An integer value that reflects the seconds within the minute.
  537. This is an integer ranging from 0 to 59.
  538. ##### Examples
  539. ```php
  540. $worksheet->setCellValue('A1', 'Time String')
  541. ->setCellValue('A2', '31-Dec-2008 17:30:20')
  542. ->setCellValue('A3', '14-Feb-2008 4:20 AM')
  543. ->setCellValue('A4', '14-Feb-2008 4:45:59 PM');
  544. $worksheet->setCellValue('B2', '=SECOND(A2)')
  545. ->setCellValue('B3', '=SECOND(A3)');
  546. ->setCellValue('B4', '=SECOND(A4)');
  547. $retVal = $worksheet->getCell('B2')->getCalculatedValue();
  548. // $retVal = 20
  549. $retVal = $worksheet->getCell('B3')->getCalculatedValue();
  550. // $retVal = 0
  551. $retVal = $worksheet->getCell('B4')->getCalculatedValue();
  552. // $retVal = 59
  553. ```
  554. ```php
  555. $retVal = call_user_func_array(
  556. array('PHPExcel_Calculation_Functions', 'SECONDOFMINUTE'),
  557. array('09:30:17')
  558. );
  559. // $retVal = 17
  560. ```
  561. ##### Notes
  562. Note that the PHPExcel function is PHPExcel_Calculation_Functions::SECONDOFMINUTE() when the method is called statically.
  563. #### TIME
  564. Not yet documented.
  565. #### TIMEVALUE
  566. Not yet documented.
  567. #### TODAY
  568. Not yet documented.
  569. #### WEEKDAY
  570. The WEEKDAY function returns the day of the week for a given date. The day is given as an integer ranging from 1 to 7, although this can be modified to return a value between 0 and 6.
  571. ##### Syntax
  572. ```
  573. WEEKDAY(datetime [, method])
  574. ```
  575. ##### Parameters
  576. **datetime** Date.
  577. An Excel date value, PHP date timestamp, PHP date object, or a date represented as a string.
  578. **method** An integer flag (values 0, 1 or 2)
  579. This is a flag that determines which method to use in the calculation, based on the values listed below:
  580. method | Description
  581. :-----:|------------------------------------------
  582. 0 | Returns 1 (Sunday) through 7 (Saturday).
  583. 1 | Returns 1 (Monday) through 7 (Sunday).
  584. 2 | Returns 0 (Monday) through 6 (Sunday).
  585. The method value defaults to 1.
  586. ##### Return Value
  587. **integer** An integer value that reflects the day of the week.
  588. This is an integer ranging from 1 to 7, or 0 to 6, depending on the value of method.
  589. ##### Examples
  590. ```php
  591. $worksheet->setCellValue('A1', 'Date String')
  592. ->setCellValue('A2', '31-Dec-2008')
  593. ->setCellValue('A3', '14-Feb-2008');
  594. $worksheet->setCellValue('B2', '=WEEKDAY(A2)')
  595. ->setCellValue('B3', '=WEEKDAY(A3,0)')
  596. ->setCellValue('B4', '=WEEKDAY(A3,2)');
  597. $retVal = $worksheet->getCell('B2')->getCalculatedValue();
  598. // $retVal = 12
  599. $retVal = $worksheet->getCell('B3')->getCalculatedValue();
  600. // $retVal = 2
  601. $retVal = $worksheet->getCell('B4')->getCalculatedValue();
  602. // $retVal = 2
  603. ```
  604. ```php
  605. $retVal = call_user_func_array(
  606. array('PHPExcel_Calculation_Functions', 'DAYOFWEEK'),
  607. array('14-July-2008')
  608. );
  609. // $retVal = 7
  610. ```
  611. ##### Notes
  612. Note that the PHPExcel function is PHPExcel_Calculation_Functions::DAYOFWEEK() when the method is called statically.
  613. #### WEEKNUM
  614. Not yet documented.
  615. #### WORKDAY
  616. Not yet documented.
  617. #### YEAR
  618. The YEAR function returns the year of a date.
  619. ##### Syntax
  620. ```
  621. YEAR(datetime)
  622. ```
  623. ##### Parameters
  624. **datetime** Date.
  625. An Excel date value, PHP date timestamp, PHP date object, or a date represented as a string.
  626. ##### Return Value
  627. **integer** An integer value that reflects the month of the year.
  628. This is an integer year value.
  629. ##### Examples
  630. ```php
  631. $worksheet->setCellValue('A1', 'Date String')
  632. ->setCellValue('A2', '17-Jul-1982')
  633. ->setCellValue('A3', '16-Apr-2009');
  634. $worksheet->setCellValue('B2', '=YEAR(A2)')
  635. ->setCellValue('B3', '=YEAR(A3)');
  636. $retVal = $worksheet->getCell('B2')->getCalculatedValue();
  637. // $retVal = 1982
  638. $retVal = $worksheet->getCell('B3')->getCalculatedValue();
  639. // $retVal = 2009
  640. ```
  641. ```php
  642. $retVal = call_user_func_array(
  643. array('PHPExcel_Calculation_Functions', 'YEAR'),
  644. array('14-July-2001')
  645. );
  646. // $retVal = 2001
  647. ```
  648. ##### Notes
  649. There are no additional notes on this function
  650. ### YEARFRAC
  651. Not yet documented.