• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

calculating days in mySQL

I am working on a MySQL query I need to calculate days depending on today and a date field I pull
what I need is DateTime.Now - onLocationDatewTime as Days
How can I do that?
SELECT jobid, 
       company, 
       wellname, 
       rig, 
       rignumber, 
       onlocationdatetime, 
       offlocationdatetime, 
       IF(jobinprogress = 1, 'Active', 'Initiated') AS 'Status' 
FROM   job 
WHERE  ( jobinprogress = TRUE 
          OR jobinitiated = TRUE ) 
ORDER  BY jobid ASC;  

Open in new window

0
r3nder
Asked:
r3nder
  • 2
1 Solution
 
StampelCommented:
I think you are after DATE_SUB.
SELECT DATE_SUB(NOW(), INTERVAL 4 day);
0
 
r3nderAuthor Commented:
Thanks
I went with DateDIFF(NOW(),onlocationdateTime)
0
 
StampelCommented:
yeah that will do the trick !
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now