Solved

calculating days in mySQL

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

810 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