简体   繁体   English

日期格式(php&mysql)

[英]Date format (php&mysql)

I would like to have the german date format. 我想要德语日期格式。 In my table in phpmyadmin I have got the format type "DATE" and I am struggling in my query now. 在phpmyadmin的表格中,我的格式类型为“ DATE”,我现在在查询中苦苦挣扎。

$sql    =   "SELECT * 
         FROM workeroffers
         WHERE 0=0"
         .( $w_destrict ? " AND w_destrict LIKE '$w_destrict'":"" )
         .( $w_select ? " AND w_select LIKE '$w_select'":"" )
         .( $w_mjobs > "" ? " AND ( ".ltrim( $w_mjobs," OR" )." )":"" )
         .( $w_mdestrict > "" ? " AND ( ".ltrim( $w_mdestrict," OR" )." )":"" )
         ." ORDER BY DATE_FORMAT( w_date, '%d.%m.%Y') AS w_date ASC;"; 

Something went wrong in this query and I am getting no result. 该查询出了点问题,但没有任何结果。 Any idears? 有想法吗? Sorry, first time that I am doing it. 抱歉,我第一次这样做。

Here it is working, but in the wrong date format: 它在这里工作,但日期格式错误:

$sql    =   "SELECT * 
         FROM joboffers
         WHERE 0=0"
         .( $j_destrict ? " AND j_destrict LIKE '".$j_destrict."'":"" )
         .( $j_select ? " AND j_select LIKE '".$j_select."'":"" )
         .( $j_mjobs > "" ? " AND ( ".ltrim( $j_mjobs," OR" )." )":"" )
         .( $j_mdestrict > "" ? " AND ( ".ltrim( $j_mdestrict," OR" )." )":"" )
         ." ORDER BY j_date ASC;";

It is a diffrent table. 这是一个不同的表。 Above it was just a try. 上面只是一个尝试。 I tought, it could go in the right direction. 我坚强,它可能会朝着正确的方向发展。

Here is my code for the result: 这是我的结果代码:

<div class="table_padding">
<table class="responsive">
    <tr>
        <th>Jobart</th>
        <th>Stadteil</th>
        <th>Berufsfeld</th>
        <th class="table_titel">Title</th>
        <th>Vergütung</th>
        <th>Gesucht ab(Datum)</th>
        <th>Weitere Informationen</th>
    </tr>
    <?php

        foreach ( $inseration as $value ) { 

    ?>

    <tr>
        <td><?= $value['w_select'] ?></td>
        <td><?= $value['w_destrict'] ?></td>
        <td><?= $value['w_cat'] ?></td>
        <td class="table_titel"><?= $value['w_title'] ?></td>
        <td><?= $value['w_cash'] ?></td>
        <td><?= $value['w_date'] ?></td>
        <td><a href="index.php?site=Jobsuche_Inserat&w_id=

            <?php
                echo $value['w_id'];

                    if( $w_select ){
                        echo '&w_select=' . $value['w_select'];
                    }
                    if( $w_destrict ){ echo '&w_destrict=' . $value['w_destrict'];
                    }
                    if( $w_mjobs > "" ){ 
                    echo '&matches_job=' . implode(',', $_REQUEST['matches_job']); 
                    }
                    if( $w_mdestrict > "" ){ 
                    echo '&matches_destrict=' . implode( ',', $_REQUEST['matches_destrict'] ); 
                    }

            ?>

        ">Weiter</a></td>
    </tr>
<?php

        }

?>
</table>

Maby I tought wrong, I just want to have the output in the german date format!! Maby我错了,我只想以德语日期格式输出!

Edit: OK cool, it is working with the correct date, but it is not ordered by date now. 编辑:好的,很不错,它正在使用正确的日期,但是现在没有按日期排序。 What did I wrong? 我怎么了

$sql    =   "SELECT DATE_FORMAT(w_date, '%d.%m.%Y') AS w_date, w_id, w_userid, w_select, w_cat, w_destrict, w_cash, w_title, w_desc, w_pic, w_email, w_phone, w_fax
         FROM workeroffers
         WHERE 0=0"
         .( $w_destrict ? " AND w_destrict LIKE '$w_destrict'":"" )
         .( $w_select ? " AND w_select LIKE '$w_select'":"" )
         .( $w_mjobs > "" ? " AND ( ".ltrim( $w_mjobs," OR" )." )":"" )
         .( $w_mdestrict > "" ? " AND ( ".ltrim( $w_mdestrict," OR" )." )":"" )
         ." ORDER BY w_date ASC;";

尝试使用日期格式中的破折号替换句点,如下所示:

." ORDER BY DATE_FORMAT( w_date, '%d-%m-%Y') AS w_date ASC;";  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM