473,406 Members | 2,894 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.

Comparing date columns in Sql

1
Hi

I have a database table that has to date columns. A purchase_start_date and a purchase_end_date. I want to write a query to find all rows where the purchase_end_date is no longer than 90 days after the purchase_start_date. My dates are in Unix time.

Can anyone help me?
Jul 5 '07 #1
1 1512
dafodil
392 256MB
Hi

I have a database table that has to date columns. A purchase_start_date and a purchase_end_date. I want to write a query to find all rows where the purchase_end_date is no longer than 90 days after the purchase_start_date. My dates are in Unix time.

Can anyone help me?
If you stored it in Timestamp you can easily compare it Subtracting the end-date to 90...

for example the statement
SELECT SUBDATE('1998-01-02 12:00:00', 31);
will return a value
'1997-12-02 12:00:00'

where 31= number of days....

Now the idea is to compare it with your own select statement....

Expand|Select|Wrap|Line Numbers
  1.  Select * FROM table where `purchase_start_date`>=SUBDATE(`purchase_end_date`, 90)
Something like that....

Why >= because it returns date....
If the result is equal to purchase_start_date It means that the days is equal to 90...
But if the result is greater than purchase_start_date it means that the days is less than 90....
Jul 5 '07 #2

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

Similar topics

6
by: teddysnips | last post by:
I have a table called WorkItem. It models a chunk of work done during a working day. It has two columns that I'm interested in: Start (smalldatetime) - the TIME the work block is begun...
3
by: laredotornado | last post by:
Hi, I have two columns, both MySQL 4 DATETIME types ... TABLE1.depart_day TABLE2.depart_day and both are indexed. The problem is, all of TABLE1's dates have a time of midnight (e.g....
5
by: Kermit Piper | last post by:
Hello, I am comparing two date values, one from a database and one that has been converted from a hard-coded string into an actual Date type. So far so good. The problem I'm having is that one...
0
by: ccshine via DotNetMonster.com | last post by:
I'm working on an app that implements a Structure to store a recordset in an ArrayList. I used this setup to bind to a DataGrid and it worked out so well, I thought it might be a better solution...
21
by: Kristaps | last post by:
Hi everyone! I have some questions, maybe someone can help me... I write script for table comparing, but it works wery slovly. There is the script, can anyone give some tip how can I make this...
2
by: Shum | last post by:
Hi! i am working on a hospital data base. i have two tables Administration and knowlege base. in Administration i have columns ID, NumberOfDoctors etc, and in KnowlegeBase i have some similar...
1
by: RiotZamber | last post by:
Hi, I'm new to DB2 so I apologize if this is a dumb question. :) I have this table with 2 columns col_date (varchar(8)) (eg. 20070813) (yyyyMmdd) col_time (varchar(6)) (eg. 1525) (HHmm) ...
7
by: bcw802000 | last post by:
Thanks ahead of time you’re your expert advice. Here is the scenario: I have several Queries that finally end up like the following. Filekey | Date | Last Name | First Name | Sum of dollars |...
0
by: sharsy | last post by:
Hi, I've setup a query that compares the difference (in years) between two date fields (Joining Date & Date Cancelled) and then totals how many people fit into each category (0 years, 1 year, 2...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.