Solved

calculating days in mySQL

Posted on 2014-10-31
3
405 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 500 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now