Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

calculating days in mySQL

Posted on 2014-10-31
3
Medium Priority
?
436 Views
Last Modified: 2014-10-31
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
Comment
Question by:r3nder
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
Stampel earned 2000 total points
ID: 40415555
I think you are after DATE_SUB.
SELECT DATE_SUB(NOW(), INTERVAL 4 day);
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40415563
Thanks
I went with DateDIFF(NOW(),onlocationdateTime)
0
 
LVL 7

Expert Comment

by:Stampel
ID: 40415569
yeah that will do the trick !
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we’ll look at how to deploy ProxySQL.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question