# visualizer/3.7.4/vendor/phpoffice/phpspreadsheet/samples/Calculations/DateTime/TIMEVALUE.php

Visualizer – Tables &amp; Charts Manager with Built-in AI Generator, version 3.7.4. 36 lines.

- Page: https://pluginprobe.com/plugins/visualizer/3.7.4/code/vendor/phpoffice/phpspreadsheet/samples/Calculations/DateTime/TIMEVALUE.php
- Raw: https://pluginprobe.com/plugins/visualizer/3.7.4/raw/vendor/phpoffice/phpspreadsheet/samples/Calculations/DateTime/TIMEVALUE.php
- Modified: 2019-02-24T07:50:56+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/visualizer/3.7.4/code/vendor/phpoffice/phpspreadsheet/samples/Calculations/DateTime/TIMEVALUE.php#L10-L20`.

```php
<?php

use PhpOffice\PhpSpreadsheet\Spreadsheet;

require __DIR__ . '/../../Header.php';

$helper->log('Converts a time in the form of text to a serial number.');

// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();

// Add some data
$testDates = ['3:15', '13:15', '15:15:15', '3:15 AM', '3:15 PM', '5PM', '9:15AM', '13:15AM',
];
$testDateCount = count($testDates);

for ($row = 1; $row <= $testDateCount; ++$row) {
    $worksheet->setCellValue('A' . $row, $testDates[$row - 1]);
    $worksheet->setCellValue('B' . $row, '=TIMEVALUE(A' . $row . ')');
    $worksheet->setCellValue('C' . $row, '=B' . $row);
}

$worksheet->getStyle('C1:C' . $testDateCount)
    ->getNumberFormat()
    ->setFormatCode('hh:mm:ss');

// Test the formulae
for ($row = 1; $row <= $testDateCount; ++$row) {
    $helper->log('Time String: ' . $worksheet->getCell('A' . $row)->getFormattedValue());
    $helper->log('Formula: ' . $worksheet->getCell('B' . $row)->getValue());
    $helper->log('Excel TimeStamp: ' . $worksheet->getCell('B' . $row)->getFormattedValue());
    $helper->log('Formatted TimeStamp: ' . $worksheet->getCell('C' . $row)->getFormattedValue());
    $helper->log('');
}

```
