Mostrar nombre del mes en español
Publicado por Anthony (2 intervenciones) el 16/09/2019 17:39:35
Hola, tengo un código el cual evita mostrar el año del mes de start_date si es igual al de end_date.
El problema es que me muestra las fechas sólo en inglés.
No encuentro la forma de hacerlo funcionar con setlocale
El problema es que me muestra las fechas sólo en inglés.
No encuentro la forma de hacerlo funcionar con setlocale
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
require_once 'connected.php';
$result;
$conn = dbConnect();
$sql = 'SELECT start_date, end_date FROM activeDates';
$result = $conn->query($sql);
$rows = $result->fetchall();
?>
<div class="table-responsive">
<table>
<thead>
<tr>
<th></th>
<th>Dates</th>
</tr>
</thead>
<tbody>
<?php
foreach ($rows as $row) {
?>
<tr>
<td>
<?php
$start=new DateTime($row['start_date']);
$startDay=$start->format('j');
$startMonth=$start->format('F');
$startYear=$start->format ('Y');
$end=new DateTime($row['end_date']);
$endDay=$end->format('j');
$endMonth=$end->format('F');
$endYear=$end->format('Y');
$s=(
($startMonth == $endMonth && $startYear==$endYear) ? "$startDay $startMonth till $endDay $endMonth $startYear" :
( ($startMonth!==$endMonth && $startYear==$endYear) ? "$startDay $startMonth till $endDay $endMonth $startYear" :
( ($startMonth==$endMonth && $startYear!==$endYear) ? "$startDay $startMonth $startYear till $endDay $endMonth $endYear" :
"$startDay $startMonth $startYear till $endDay $endMonth $endYear"
)
)
);
echo $s.PHP_EOL;
?>
</td>
</tr>
<?php } ?>
Valora esta pregunta


0