babli sharma
babli sharma

Reputation: 17

How to subtract time from current time in mysql

Hi want to subtract 1 min from current time in my sql i used following query but it is showing null

query

SELECT curtime() - INTERVAL '00:00:30' SECOND

what should i do to get my result

Any help will be appreciated

Upvotes: 1

Views: 3114

Answers (2)

Yatin Mistry
Yatin Mistry

Reputation: 1264

Try this

 SELECT TIMEDIFF(curtime(),'00:00:30');

In Seconds

SELECT TIME_TO_SEC(TIMEDIFF(curtime(),'00:00:30'));

Or Static One

   SELECT TIME_TO_SEC(TIMEDIFF('00:01:00','00:00:30'))

Upvotes: 2

M Khalid Junaid
M Khalid Junaid

Reputation: 64476

For minute you can do so

SELECT curtime() - INTERVAL 1 MINUTE

Another one will be something like below but its return type will string no time

SELECT 
SUBSTRING_INDEX(
NOW() - INTERVAL 1 MINUTE
,' ',-1)

Demo

Upvotes: 0

Related Questions