473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

calculating DATE differences

I am doing a registry system where you have to register and pay within 2 months before action is taken. I am trying to create an SQL query to sort out registered users who have yet to pay in a specific time.

i come to a solution where you have to...

select * from members where PaidStatus = 'new' && CURDATE() > DateReg + 2 months;

but iam unsure how to calculate the 2months, i thought maybe a uni time which is around 5000000 but does not work. any suggestions.
Feb 8 '08 #1
1 1202
mwasif
802 Expert 512MB
Hi tdsmithj,

Welcome to TSDN!!!

You can calculate 2 months duration from registration date with the help of MySQL's built in function DATE_ADD().

The following query will fetch all those members who have not paid within 2 months
Expand|Select|Wrap|Line Numbers
  1. select * from members where PaidStatus = 'new' AND CURDATE() > DATE_ADD(DateReg, INTERVAL 2 MONTH);
You can rewrite the query in this way too (this query is more efficient)
Expand|Select|Wrap|Line Numbers
  1. select * from members where PaidStatus = 'new' AND DATE_SUB(CURDATE(), INTERVAL 2 MONTH) > DateReg;
Feb 9 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Ralph Freshour | last post by:
What's a good way to calculate the number of days between two dates in the following format: 2003-07-15 2003-08-02 I've looked at the PHP date functions but I'm still a bit lost...
4
by: Hans Gruber | last post by:
Hi all, I have been struggling with a problem all day, I have been unable to come up with a working solution. I want to write a function which takes 2 unix timestamps and calculates the...
1
by: Tony Williams | last post by:
I have a table with two fields, txtvalue (a number field) and txtmonth ( a date/time field). I want to create a report that shows the difference in value between the value in txtvalue in one value...
1
by: pauly | last post by:
Hello All, I have been trying to create a query that extracts data from a table and calculates the elapsed time between records. The table called "Imported_table". I need to be able to calculate...
2
by: Gustavo G. Rondina | last post by:
It is possible to caclulate every year's easter using simple mathematical operations. Here is a code that does the trick: http://www.brlivre.org/c/easter.c I found the math scheme in an...
0
by: hlam | last post by:
Help - Calculating the total of a column in a data grid -- when data grid is part of Master-Detail set-up I have setup a Master-Detail form using Visual Studio.Net. A ListBox is the (Master)...
1
by: b.beeching | last post by:
Not sure if my subject is entirely accurate but here goes. I need to calculate the date difference between a date A and a date B... however date B relies entily on date A. EG: i have an advert...
1
by: rodneyeid | last post by:
Hi, I have an attendance machine which saves records in an Access Database in the following format : UserID DATE/TIME Checktype where if checktype is 0 then its check in and if it is 1 then it...
2
by: ncsthbell | last post by:
I am having problems getting the end date to calculate correctly. I start with Quarter '03/02', (YY/QTR), for this it means it is for the 2nd qtr of 2003. My goal is to get the begin & end dates...
25
by: Blaize | last post by:
Hi, I'm having an issue trying to calculate time. Its okay if the value does not exceed 24 hours otherwise I get a date and hours listed. For example, I have a loop which looks through a table...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.