How to Get 12 hours ago Datetime in MySQL?

engrmahabub
Mahabubur Rahman
Published on May, 30 2024 1 min read 0 comments
image

Problem : 

We would like to get 12 hours ago datetime in MySQL database. So we need to execute query to solve this. 

 

Solution :

Write bellow query to get12 hours ago datetime - 

 

SELECT NOW(), DATE_SUB(NOW(), INTERVAL '12' HOUR) AS date_time 

Output :

Discussions : 

To get 12 hours ago datetime you need to substract 12 hours from current time. You need to use NOW() to get current date time. After then you need to substract 12 hours from current time using DATE_SUB() function. Here you need to substract 12 hours as DATE_SUB(NOW(), INTERVAL 12 Hour)

0 Comments