开发者

how to subtract 12 hours 30 minutes from the MySQL from date field [duplicate]

This question already has answers here: 开发者_开发技巧 How to subtract hours from a datetime in MySQL? (3 answers) Closed 9 months ago.

I have reduce or subtract 12 hours 30 minutes from the 2011-04-26 05:00:00(in the format YYYY-MM-DD HH:MM:SS) IN MySQL database.

The output should be 2011-04-25 16:30:00.

Are there any date function we can use and subtract?


DATE_SUB(`date`,INTERVAL '12:30' HOUR_MINUTE)

Checkout date and time functions of mysql


select '2011-04-26 05:00:00' - interval 12 * 60 + 30 minute


The date/time functions are documented here:

  • http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

You probably want DATE_SUB().


Fine, This can be done by DATE_ADD() function in MySQL

select lastname, 
        changedat, date_add(changedat, interval - '12:30' hour) as newdate
    from employee_audit;

lastname and changedat is field name and employee_audit is table name.

how to subtract 12 hours 30 minutes from the MySQL from date field [duplicate]

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜