开发者

Need to extract date and month from mysql field in the query

开发者 https://www.devze.com 2023-04-05 19:47 出处:网络
I have a mysql field emp_join_date of type timestamp and its in the format yyyy-mm-dd hh:mm:ss . Now I need to retrieve the month and date only from that field and in the query itself . How can I able

I have a mysql field emp_join_date of type timestamp and its in the format yyyy-mm-dd hh:mm:ss . Now I need to retrieve the month and date only from that field and in the query itself . How can I able to do this ?

$sql = "
        SELECT
            emp_id,emp_status,emp_type,emp_join_date

        FROM
            tbl_events
        WHERE
            event_show = 'all'
        AND
            event_status != 'disabled'
        ORDER BY
            RAND开发者_运维技巧()
        LIMIT 0,4   
    ";


DATE(emp_join_date) for date and MONTH(emp_join_date) for month

`$sql = "
    SELECT
        emp_id,emp_status,emp_type,DATE(emp_join_date) as dt, MONTH(emp_join_date) as mt

    FROM
        tbl_events
    WHERE
        event_show = 'all'
    AND
        event_status != 'disabled'
    ORDER BY
        RAND()
    LIMIT 0,4   
";`


You can use the function DATEFORMAT() to view just the date and month.

Refer http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format

You can aslo use the MONTH and DAYOFMONTH functions if you want the month and date in separate fields

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号