I have two SQL statements:
Statement #1
SELECT CARRIER_REFERENCE_NUMBER,
CURRENT_FLEET_SIZE,
trunc(Fleet_Size_Effective_From_Date),
trunc(Fleet_Size_Effective_To_Date)
FROM CAPS.CARRIER_FLEET_SIZE_HISTORY
WHERE CARRIER_REFERENCE_NUMBER = 481
AND trunc(Fleet_Size_Effective_TO_Date) >=
TO_DATE('24-FEB-2003') AND trunc(Fleet_Size_Effective_From_Date) <=
TO_DATE('24-FEB-2004')
ORDER BY CARRIER_REFERENCE_NUMBER,
Fleet_Size_Effective_From_Date,
Fleet_Size_Effective_To_Date,
CURRENT_FLEET_SIZE
************************************************** ****************************
Statement #2
SELECT CARRIER_REFERENCE_NUMBER,
CURRENT_FLEET_SIZE,
TRUNC(Fleet_Size_Effective_From_Date) AS START_DATE,
TRUNC(Fleet_Size_Effective_To_Date) AS END_DATE
FROM CAPS.CARRIER_FLEET_SIZE_HISTORY
WHERE CARRIER_REFERENCE_NUMBER = 481
AND TO_DATE(Fleet_Size_Effective_TO_Date,'DD-MON-YYYY') >=
TO_DATE(ADD_MONTHS(SYSDATE, -12),'DD-MON-YYYY')
AND TRUNC(Fleet_Size_Effective_From_Date) <=
TO_CHAR(SYSDATE,'DD-MON-YYYY')
ORDER BY CARRIER_REFERENCE_NUMBER,
Fleet_Size_Effective_From_Date,
Fleet_Size_Effective_To_Date,
CURRENT_FLEET_SIZE
Statement #1 returns 13 records....statement #2 returns 5 records.
Both Fleet_Size_Effective_TO_Date and Fleet_Size_Effective_From_Date
are of a DATE datatype. I am trying to restrict the query to the
sysdate as an end date, and sysdate - 12 months as a start date.
What's wrong with my date math?
Any input into this would be greatly appreciated. 1 8317
Alex wrote: I have two SQL statements:
Statement #1
SELECT CARRIER_REFERENCE_NUMBER, CURRENT_FLEET_SIZE, trunc(Fleet_Size_Effective_From_Date), trunc(Fleet_Size_Effective_To_Date) FROM CAPS.CARRIER_FLEET_SIZE_HISTORY WHERE CARRIER_REFERENCE_NUMBER = 481 AND trunc(Fleet_Size_Effective_TO_Date) >= TO_DATE('24-FEB-2003') AND trunc(Fleet_Size_Effective_From_Date) <= TO_DATE('24-FEB-2004') ORDER BY CARRIER_REFERENCE_NUMBER, Fleet_Size_Effective_From_Date, Fleet_Size_Effective_To_Date, CURRENT_FLEET_SIZE
************************************************** **************************** Statement #2
SELECT CARRIER_REFERENCE_NUMBER, CURRENT_FLEET_SIZE, TRUNC(Fleet_Size_Effective_From_Date) AS START_DATE, TRUNC(Fleet_Size_Effective_To_Date) AS END_DATE FROM CAPS.CARRIER_FLEET_SIZE_HISTORY WHERE CARRIER_REFERENCE_NUMBER = 481 AND TO_DATE(Fleet_Size_Effective_TO_Date,'DD-MON-YYYY') >= TO_DATE(ADD_MONTHS(SYSDATE, -12),'DD-MON-YYYY') AND TRUNC(Fleet_Size_Effective_From_Date) <= TO_CHAR(SYSDATE,'DD-MON-YYYY') ORDER BY CARRIER_REFERENCE_NUMBER, Fleet_Size_Effective_From_Date, Fleet_Size_Effective_To_Date, CURRENT_FLEET_SIZE
Statement #1 returns 13 records....statement #2 returns 5 records.
Both Fleet_Size_Effective_TO_Date and Fleet_Size_Effective_From_Date are of a DATE datatype. I am trying to restrict the query to the sysdate as an end date, and sysdate - 12 months as a start date. What's wrong with my date math? Any input into this would be greatly appreciated.
Sysdate is today - not Feb, 24!
Also, the second query compares dates with characters (you
do use TO_CHAR(SYSDATE...)) and may thus not perform as well
--
Regards,
Frank van Bortel This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robert Mark Bram |
last post by:
Howdy All!
I am trying to write a very brief comparison of the Date and Math objects in
terms of instance v static objects. What I have below is my best so far. Any
criticisms or suggestions are...
|
by: Scott Knapp |
last post by:
Good Day -
I have a form which sets the current date, as follows:
<script type="text/javascript">
xx=new Date()
dd=xx.getDate()
mm=xx.getMonth()+1
yy=xx.getYear()
mmddyy=mm+"/"+dd+"/"+yy...
|
by: Richard Hollenbeck |
last post by:
I'm trying to write some code that will convert any of the most popular
standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan
1908) and compare the first with the second and...
|
by: Jim Davis |
last post by:
Before I reinvent the wheel I thought I'd ask: anybody got a code snippet
that will convert the common ISO8601 date formats to a JS date?
By "common" I mean at the least ones described in this...
|
by: jerry.ranch |
last post by:
I have a need to convert simple dates (i.e. 02/14/2005) to a number,
do some math, and convert back to a date. (in a simple query).
The math involves adding or substracting days, and days of the...
|
by: Sam |
last post by:
How do I convert Julian Date to Calendar Date in ASP.Net 1.1 based on
following guideline found at Internet?
To convert Julian date to Gregorian date:
double JD = 2299160.5;
double Z =...
|
by: Woody Splawn |
last post by:
I am trying to determine the age of a person based on two dates, the Date of
Birth and Today().
I have a function that does this but it is kludgey and is giving me an age
that is pretty close...
|
by: jamesyreid |
last post by:
Hi,
I'm really sorry to post this as I know it must have been asked
countless times before, but I can't find an answer anywhere.
Does anyone have a snippet of JavaScript code I could borrow...
|
by: Mtek |
last post by:
Hi,
We have a form where the user selects a date from a calendar, the date
is in the format May 23, 2008.
The date in the datebase is in the format 05212008.
What we need to do is get the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |