I have two SQL statements:
Statement #1
SELECT CARRIER_REFEREN CE_NUMBER,
CURRENT_FLEET_S IZE,
trunc(Fleet_Siz e_Effective_Fro m_Date),
trunc(Fleet_Siz e_Effective_To_ Date)
FROM CAPS.CARRIER_FL EET_SIZE_HISTOR Y
WHERE CARRIER_REFEREN CE_NUMBER = 481
AND trunc(Fleet_Siz e_Effective_TO_ Date) >=
TO_DATE('24-FEB-2003') AND trunc(Fleet_Siz e_Effective_Fro m_Date) <=
TO_DATE('24-FEB-2004')
ORDER BY CARRIER_REFEREN CE_NUMBER,
Fleet_Size_Effe ctive_From_Date ,
Fleet_Size_Effe ctive_To_Date,
CURRENT_FLEET_S IZE
*************** *************** *************** *************** *************** ***
Statement #2
SELECT CARRIER_REFEREN CE_NUMBER,
CURRENT_FLEET_S IZE,
TRUNC(Fleet_Siz e_Effective_Fro m_Date) AS START_DATE,
TRUNC(Fleet_Siz e_Effective_To_ Date) AS END_DATE
FROM CAPS.CARRIER_FL EET_SIZE_HISTOR Y
WHERE CARRIER_REFEREN CE_NUMBER = 481
AND TO_DATE(Fleet_S ize_Effective_T O_Date,'DD-MON-YYYY') >=
TO_DATE(ADD_MON THS(SYSDATE, -12),'DD-MON-YYYY')
AND TRUNC(Fleet_Siz e_Effective_Fro m_Date) <=
TO_CHAR(SYSDATE ,'DD-MON-YYYY')
ORDER BY CARRIER_REFEREN CE_NUMBER,
Fleet_Size_Effe ctive_From_Date ,
Fleet_Size_Effe ctive_To_Date,
CURRENT_FLEET_S IZE
Statement #1 returns 13 records....stat ement #2 returns 5 records.
Both Fleet_Size_Effe ctive_TO_Date and Fleet_Size_Effe ctive_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 8338
Alex wrote: I have two SQL statements:
Statement #1
SELECT CARRIER_REFEREN CE_NUMBER, CURRENT_FLEET_S IZE, trunc(Fleet_Siz e_Effective_Fro m_Date), trunc(Fleet_Siz e_Effective_To_ Date) FROM CAPS.CARRIER_FL EET_SIZE_HISTOR Y WHERE CARRIER_REFEREN CE_NUMBER = 481 AND trunc(Fleet_Siz e_Effective_TO_ Date) >= TO_DATE('24-FEB-2003') AND trunc(Fleet_Siz e_Effective_Fro m_Date) <= TO_DATE('24-FEB-2004') ORDER BY CARRIER_REFEREN CE_NUMBER, Fleet_Size_Effe ctive_From_Date , Fleet_Size_Effe ctive_To_Date, CURRENT_FLEET_S IZE
*************** *************** *************** *************** *************** *** Statement #2
SELECT CARRIER_REFEREN CE_NUMBER, CURRENT_FLEET_S IZE, TRUNC(Fleet_Siz e_Effective_Fro m_Date) AS START_DATE, TRUNC(Fleet_Siz e_Effective_To_ Date) AS END_DATE FROM CAPS.CARRIER_FL EET_SIZE_HISTOR Y WHERE CARRIER_REFEREN CE_NUMBER = 481 AND TO_DATE(Fleet_S ize_Effective_T O_Date,'DD-MON-YYYY') >= TO_DATE(ADD_MON THS(SYSDATE, -12),'DD-MON-YYYY') AND TRUNC(Fleet_Siz e_Effective_Fro m_Date) <= TO_CHAR(SYSDATE ,'DD-MON-YYYY') ORDER BY CARRIER_REFEREN CE_NUMBER, Fleet_Size_Effe ctive_From_Date , Fleet_Size_Effe ctive_To_Date, CURRENT_FLEET_S IZE
Statement #1 returns 13 records....stat ement #2 returns 5 records.
Both Fleet_Size_Effe ctive_TO_Date and Fleet_Size_Effe ctive_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 most welcome!
Date is an instance object.
You use Date by creating instances of it
- you call methods on those instances.
- you change data to do with each instance.
|
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
document.write(mmddyy)
|
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 calculate days, months, and
years. This is not for a college course. It's for my own personal
genealogy website. I'm stumped about the code. I'm working on it but not
making much progress. Is there any free code available anywhere? I know it...
|
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 W3C note:
http://www.w3.org/TR/NOTE-datetime
For my requirements the code would be need to be open sourceable under the
BSD license.
|
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 week .
I've used the weekday() function to convert dates to numberic days of
the week (1-7)
I've used cdbl (date) to convert a date to a serial number, but then I
do math with the number and I can't seem to convert this back to a
date.
| |
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 = Math.Floor(JD+0.5);
double W = Math.Floor((Z - 1867216.25)/36524.25);
double X = Math.Floor(W/4);
|
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 but only because I have figured into the equation
(manually) the approximate number of leap years.
The code reads:
Dim TS As New TimeSpan
Dim NumDays As Integer
|
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 which
calculated the difference in years and days between two dates, and
takes leap years into account?
I'm calculating the difference in the usual way, i.e....
|
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 starting and ending date of the week for
the date selected in the form: May 23, 2008, and then get the records
from the database where the dates fall within that range.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |