9

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?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
gourav
  • 1,397
  • 5
  • 20
  • 31

4 Answers4

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

Checkout date and time functions of mysql

Shakti Singh
  • 84,385
  • 21
  • 134
  • 153
6
select '2011-04-26 05:00:00' - interval 12 * 60 + 30 minute
Nicola Cossu
  • 54,599
  • 15
  • 92
  • 98
3

The date/time functions are documented here:

You probably want DATE_SUB().

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
0

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.

enter image description here

Solomon Suraj
  • 1,162
  • 8
  • 8