Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

calculating days in mySQL

Posted on 2014-10-31
3
Medium Priority
?
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

704 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