如何仅使用PHP在表中显示日期而不是时间

时间:2017-08-02 16:41:15

标签: php mysql

这是我目前的表格:

enter image description here

这是相应的PHP代码:

                        <?php
                            //include 'database.php';
                            $pdo2 = Database::connect();
                            $sql2 = "SELECT id,
                                    full_name,
                                    owner_name awardee,
                                    owner awardee_email,
                                    (select concat(user_name,' ',user_last_name) from users where email = who_created) awarder,
                                    creation_time
                                    FROM awards, award_types
                                    where who_created = ? and awards_type=type_id";
                            $q2 = $pdo->prepare($sql2);
                            $q2->execute(array($_COOKIE["email"]));
                            $date = date('Y-m-d', strtotime($date));
                            foreach ($q2 as $row) {
                                echo '<tr>';
                                echo '<td>'. $row['id'] . '</td>';
                                echo '<td>'. $row['full_name'] . '</td>';
                                echo '<td>'. $row['awardee'] . '</td>';
                                echo '<td>'. $row['awardee_email'] . '</td>';
                                echo '<td>'. $row['awarder'] . '</td>';
                                echo '<td>'. $row['creation_time'] . '</td>';
                                echo '<td><a class="btn" href="DeleteAward.php?id='.$row['id'].'">Delete Award</a></td>';
                                echo '</tr>';
                           }
                           Database::disconnect();
                          ?>

我只想在&#34;日期&#34;下显示日期,而不是时间。柱。我从其他帖子中读到我需要使用某种date(creation_time)DATE_FORMAT(creation_time)命令,但我尝试了两种命令,他们只是将我的&#34;日期&#34;栏目空白。

我怀疑我也需要更改echo '<td>'. $row['creation_time'] . '</td>';行,但我无法找到有关如何操作的指南。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:3)

有两种方法可以解决这个问题:

MySQL方式:

$productCatalog = myCatalog
$classificationCatalog = myClassification

$catalogVersion = catalogversion(catalog(id[default = $productCatalog]), version[default = 'Staged'])[unique = true, default = $productCatalog:Staged]
$clAttrModifiers = system = '$classificationCatalog', version = '1.0', translator = de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator, lang = es
//Q_1001 is the ClassAttributeAssignment ID
$feature1 = @Q_1001 [$clAttrModifiers];
//123012 is the product code and
INSERT_UPDATE  Product; code[unique = true]; $feature1; $catalogVersion
; 123012 ; TEST VALUE;

或PHP方式:

INSERT_UPDATE  Product;code[unique = true];@Q_1001 [system = 'myClassification', version = '1.0', translator = de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator, lang = es];catalogversion(catalog(id[default = myCatalog]), version[default = 'Staged'])[unique = true, default = myCatalog:Staged];# invalid special value translator class 'de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator' - cannot create due to java.lang.InstantiationException: de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator
,,,,invalid special value translator class 'de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator' - cannot create due to java.lang.InstantiationException: de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator;123012;TEST VALUE;

修改以下是每种方式的确切代码:

MySQL的:

SELECT DATE(creation_time) AS creation_time

和PHP版本:

$creation_date = date('Y-m-d', strtotime($row['creation_time']));