473,394 Members | 1,797 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,394 software developers and data experts.

DATEDIFF function in Oracle

17
for portability in SQL query ie a query written for one DB runs fine for other
i try to standardize our SQL queries as far as i can....
For finding the date difference we have:

DATEDIFF function in SQL Server
- operator in Oracle ...

i want to Sync this also how would i do that

i tried to create same name function in Oracle but having problem... of parameter type....what interval type should i take so that it works like SQL server DATEDIFF function.
Aug 13 '07 #1
4 112852
debasisdas
8,127 Expert 4TB
If you want to write your own function well and good ,but simply if you wnat the different of 2 dates just use simple substration in oracle syntax.

ex

select date1-date2 from dual;

if u wnat to write the function both the parameters should be of DATE data type and the return type can be number.
Aug 13 '07 #2
misaw
17
If you want to write your own function well and good ,but simply if you wnat the different of 2 dates just use simple substration in oracle syntax.

ex

select date1-date2 from dual;

if u wnat to write the function both the parameters should be of DATE data type and the return type can be number.
let me more clearify my requirement....

What i actually want is to run the same query on Different DB, since this query is using Oracle - operator does'nt work as required in SQL Server.
select date1-date2 from dual;


What i want is if i write in SQL Server the following query
SELECT DATEDIFF(day, myDATE, GETDATE()) AS NumberOfDays
FROM myTable

This exactly without any change run fine in oracle ... this requires the DATEDIFF function in Oracle which is not there so i want create one for this ... but what about the first parameter of this function

please see detail of DATEDIFF at following link
http://msdn2.microsoft.com/en-us/library/ms189794.aspx

but i cannot under stand what type of this parameter is day dd d

thanks for your co-operation
Aug 15 '07 #3
krispc
1
Did this ever get resolved I am fighting the exact same issue. And since Oracle does not support the ODBC TIMESTAMPDIFF function I can't quite get a handle on how to handle both databases with the same sql.
May 14 '09 #4
dthao
1
You should be able to get the number of days by subtract date1 - date2.

Example

select name, date1-date2 days from customers

name days
bob 1
jane 5
rick 10

Hope this helps.
Jun 30 '09 #5

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

Similar topics

1
by: info | last post by:
Can some one show me how to use the datediff function where the dates are being supplied through an access db. For instance, a recordset would contain these fields: DateAssigned, DateDue,...
5
by: mcbill20 | last post by:
Hello all. I have a really basic question that I hope someone has a better answer for. I apologize in advance-- I know this is probably a really basic question but I am used to Oracle rathern than...
2
by: Derrick | last post by:
I've included using Microsoft.VisualBasic, cranked up a VBCodeProvider, the only class I see in there, don't see DateDiff as a method though? Thanks in advance!! Derrick
7
by: reney | last post by:
I am trying to return the difference in minutes from a starttime and stoptime using the datediff function in a Web Project with VB.Net With: StartTime = 2/10/2006 8:46:03 PM EndTime = ...
1
by: KMEscherich | last post by:
Using Access '97 Hi there. I have a field that uses a DateDiff function to count the number of days between a DATE field and DATE(), is there a way to have the counter stop counting days when the...
7
by: JenM | last post by:
Hi. I am a novice user. I am using the datediff function in a query. I am trying to calculate the number of week days between two dates. When I use "m" as the interval, the number of weeks is...
14
by: cmdolcet69 | last post by:
I'm trying to use the DateDiff function to calculate the difference whether a shift has been setup. when i run the code below with strFirstShiftEnd as a stringor date or datetime. I get an error...
1
by: cptcanada | last post by:
Hi All, I am getting an error saying that now() is not a reconized function in my datediff function would any one know why it is not being reconized? Thanks for the help...
2
by: bandy | last post by:
Hi, I am using datediff() function to get difference between two dates. my code looks like, function dateDiff($dformat, $endDate, $beginDate) { $date_parts1 = explode($dformat,...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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
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...
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
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...

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.