Skip to content

Commit 66221bf

Browse files
authored
TEXT Function Ignores Time in DateTimeStamp (#3411)
Fix #3409. Calculate both the date and time portions when a date/time format is supplied for the TEXT function.
1 parent bef3a00 commit 66221bf

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/PhpSpreadsheet/Calculation/TextData/Format.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static function TEXTFORMAT($value, $format)
129129
$format = Helpers::extractString($format);
130130

131131
if (!is_numeric($value) && Date::isDateTimeFormatCode($format)) {
132-
$value = DateTimeExcel\DateValue::fromString($value);
132+
$value = DateTimeExcel\DateValue::fromString($value) + DateTimeExcel\TimeValue::fromString($value);
133133
}
134134

135135
return (string) NumberFormat::toFormattedString($value, $format);

tests/data/Calculation/TextData/TEXT.php

+10
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@
6161
'1-Jan-2012',
6262
'yyyy-mm-dd',
6363
],
64+
'time (issue 3409)' => [
65+
'09:01:00',
66+
'09:01',
67+
'HH:MM:SS',
68+
],
69+
'datetime' => [
70+
'15-Feb-2014 04:17:00 PM',
71+
'2014-02-15 16:17',
72+
'dd-mmm-yyyy HH:MM:SS AM/PM',
73+
],
6474
[
6575
'1 3/4',
6676
1.75,

0 commit comments

Comments
 (0)