473,795 Members | 3,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date conversion

I have dates stored as 20040904(yyyymm dd numeric) in DB2 database. I
want to get the difference between two dates. I also have the same
database in SQL Server database and I am using the following SQL to do
the arithmetic in the where clause.

SELECT CONVERT(CHAR(10 ),CONVERT(DATET IME, STR(Date1), 112), 101),
CONVERT(CHAR(10 ),CONVERT(DATET IME, STR(Date2), 112), 101)
FROM Table1, Table2
WHERE DATEDIFF(DY, CONVERT(DATETIM E, STR(Date2), 112),
CONVERT(DATETIM E, STR(Date1), 112)) > 16

I want an equivalent DB2 syntax to allow me to calculate the difference
between two dates stored as numbers in yyyymmdd numeric format.

Thanks

Nov 12 '05 #1
1 30808
Jama wrote:
I have dates stored as 20040904(yyyymm dd numeric) in DB2 database. I
want to get the difference between two dates. I also have the same
database in SQL Server database and I am using the following SQL to do
the arithmetic in the where clause.

SELECT CONVERT(CHAR(10 ),CONVERT(DATET IME, STR(Date1), 112), 101),
CONVERT(CHAR(10 ),CONVERT(DATET IME, STR(Date2), 112), 101)
FROM Table1, Table2
WHERE DATEDIFF(DY, CONVERT(DATETIM E, STR(Date2), 112),
CONVERT(DATETIM E, STR(Date1), 112)) > 16

I want an equivalent DB2 syntax to allow me to calculate the difference
between two dates stored as numbers in yyyymmdd numeric format.


The DATE function supports several different input formats.

One takes an integer (as number of days since 0001-01-01) directly. So you
could do some calculations to convert your number into the number of days.
This is not correct because it assumes 30 days per month and ignores leap
years, but you should get the idea:

VALUES DATE((<date> / 10000) * 365 + MOD(<date>, 10000) * 30 + MOD(<date>,
100))

Another version takes a string. There you have to parse your string and
rebuild it in a format accepted by DB2.

VALUES ( DATE(SUBSTR(<da te>, 1, 4) || SUBSTR(<date>, 5, 2) || SUBSTR(<date>,
7, 2))

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2189
by: nimish | last post by:
I have Month, Day and Year fields on my form. When I submit this form I want to create a valid date from all three fields before inserting into MYSQL table. I tried following: $dob=$Month."-".$Day."-".$Year; $dob = strtotime($dob); But it does not update my date field in the table. I am novice in PHP, do you know where i am making a mistake.
5
16092
by: SalimShahzad | last post by:
Dear Respected Gurus, I need a coding assistant converting from gregorian to hijri and vice versa. I have problem with this codes. the problem Gregorian to Hijri gives 100% results. when i enter this to Hijri to gregorian it either do nothing or go to next record on form. well there r two fields on form that r calc afterevents each other dates. ur assistance will be highly appreciated, if any one can tell what is wrong with this codes
4
1625
by: dhnriverside | last post by:
Hi peeps I have a datepicker control that's providing dates in the format dd/mm/yyyy (UK). I want to convert this to "yyyy-mm-dd" to store as a text field in my database (had lots of problems with date conversions using "proper" data fields). I used to use ASP, and it was easy, using a combination of Left() Mid() and
1
1641
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings set to "en-UK" and date to dd/MM/yyyy. (I'can't change it !)
1
3239
by: vadala | last post by:
The requirement is to send start data and end date from java to UI (.net) for a functionality. We are setting the time in java (1.5) before handing it over to WebService (sending to UI ) in "ASIA/KUALA_LUMPUR" (MYT) TIMEZONE. OS WIN-XP Strangely UI receives a different date. java side UI side
7
3012
by: bruce.dodds | last post by:
Access seems to be handling a date string conversion inconsistently in an append query. The query converts a YYYYMM string into a date, using the following function: CDate(Right(,2) & "/1/" & Left(,4)) I entered the string "200715" in a record to test an error condition.
2
5420
by: p.smachylo | last post by:
Hello, I am relatively new to Microsoft Access and databases in general, and have a problem - one which I think may necessitate some VBA code (or maybe just modification of the criteria section of the query. I have a table with several columns being imported into a query which will eventually be used in a report. One of the fields in the database is called 'Predicted Completion Date' and is in the format: Q# Year (formatted as text)....
2
5154
by: RN1 | last post by:
A TextBox displays the current date (in dd/mm/yyyy format) & time when a user comes to a page (e.g. 15/10/2008 1:36:39 PM). To convert the date into international format so that the remote server doesn't generate any error, this is what I am doing: --------------------------- Dim strSDate As String Dim strSTime As String Dim strStartDT As String Dim strSDateTime As String
2
2124
by: anderst | last post by:
Hi! I need help with date conversion, I need a perl-script that transform Wed Mar 28 00:00:00 GMT+02:00 2007 to 2007-03-28 I have tried to use perl modules Date::Manip and Date::Calc, but no succes so far. Maybe I am doing it the wrong way.
4
2132
maheshwag
by: maheshwag | last post by:
my code is: string sql="insert into dummy(date)values(@date) sqlcommand cmd=new sqlcommand(sql,con) cmd.parameters.Add("@date", SqlDbtype.datetime).values=maskedtextbox1.text; cmd.ExecuteNonquery();
0
9672
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, 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...
0
9519
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,...
0
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
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 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...
1
7538
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 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...
0
6780
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();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.