473,748 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

current date minus date

Hi all,

I have a field which has data as YYYYMMDD, and I have to find the age
of the person by substracting it from current date. can you please
please advice...

thanks

Jan 9 '06 #1
6 26318
vijayk wrote:
Hi all,

I have a field which has data as YYYYMMDD, and I have to find the age
of the person by substracting it from current date. can you please
please advice...


VALUES current date - date('08-01-1975')

The result is a date duration and you can find a description for those here:
http://tinyurl.com/7r7ll

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Jan 9 '06 #2
I don't think you can do that.
Not with the data in the form YYMMDD.

At least I could not make it happen.

It works if your field has data as 'YYYY-MM-DD'.
Maybe you can change that.
db2 "select * from sim.date2"
MYDATE
----------
1971-08-19
db2 "select days(current date)- days(mydate) age_in_days from sim.date2"


AGE_IN_DAYS
-----------
12563

Jan 10 '06 #3
DECLARE GLOBAL TEMPORARY TABLE A (BirthDay DATE)

INSERT INTO SESSION.A VALUES('01-07-1975')
INSERT INTO SESSION.A VALUES('01-08-1975')
INSERT INTO SESSION.A VALUES('01-09-1975')
INSERT INTO SESSION.A VALUES('01-10-1975')
INSERT INTO SESSION.A VALUES('01-11-1975')
INSERT INTO SESSION.A VALUES('01-12-1975')
INSERT INTO SESSION.A VALUES('01-13-1975')
INSERT INTO SESSION.A VALUES('01-14-1975')
INSERT INTO SESSION.A VALUES('01-15-1975')
SELECT
Birthday,
YEAR(CURRENT DATE) - YEAR(BirthDay)
+ CASE
WHEN MONTH(BirthDay) > MONTH(CURRENT DATE)
OR (MONTH(BirthDay ) = MONTH(CURRENT DATE)
AND DAY(BirthDay) >= DAY(CURRENT DATE)) THEN 1
ELSE 0
END CASE
FROM SESSION.A

DROP TABLE SESSION.A
COMMIT

HTH,
B.

Jan 10 '06 #4
OK, wasn't thinking.

DECLARE GLOBAL TEMPORARY TABLE A (BirthDay DATE)

INSERT INTO SESSION.A VALUES('01-07-1975')
INSERT INTO SESSION.A VALUES('01-08-1975')
INSERT INTO SESSION.A VALUES('01-09-1975')
INSERT INTO SESSION.A VALUES('01-10-1975')
INSERT INTO SESSION.A VALUES('01-11-1975')
INSERT INTO SESSION.A VALUES('01-12-1975')
INSERT INTO SESSION.A VALUES('01-13-1975')
INSERT INTO SESSION.A VALUES('01-14-1975')
INSERT INTO SESSION.A VALUES('01-15-1975')
SELECT
Birthday,
YEAR(CURRENT DATE) - YEAR(BirthDay)
- CASE
WHEN MONTH(BirthDay) < MONTH(CURRENT DATE)
OR (MONTH(BirthDay ) = MONTH(CURRENT DATE)
AND DAY(BirthDay) < DAY(CURRENT DATE)) THEN 1
ELSE 0
END CASE
FROM SESSION.A

DROP TABLE SESSION.A
COMMIT

Jan 10 '06 #5
Brian Tkatch wrote:
OK, wasn't thinking.

DECLARE GLOBAL TEMPORARY TABLE A (BirthDay DATE)

INSERT INTO SESSION.A VALUES('01-07-1975')
INSERT INTO SESSION.A VALUES('01-08-1975')
INSERT INTO SESSION.A VALUES('01-09-1975')
INSERT INTO SESSION.A VALUES('01-10-1975')
INSERT INTO SESSION.A VALUES('01-11-1975')
INSERT INTO SESSION.A VALUES('01-12-1975')
INSERT INTO SESSION.A VALUES('01-13-1975')
INSERT INTO SESSION.A VALUES('01-14-1975')
INSERT INTO SESSION.A VALUES('01-15-1975')
SELECT
Birthday,
YEAR(CURRENT DATE) - YEAR(BirthDay)
- CASE
WHEN MONTH(BirthDay) < MONTH(CURRENT DATE)
OR (MONTH(BirthDay ) = MONTH(CURRENT DATE)
AND DAY(BirthDay) < DAY(CURRENT DATE)) THEN 1
ELSE 0
END CASE
FROM SESSION.A

DROP TABLE SESSION.A
COMMIT


Even easier with date durations:

VALUES INT((CURRENT DATE - DATE('1975-01-08')) / 10000)

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Jan 11 '06 #6
Yes, it does. I was thinking of day of year, and how it would fail on
2/29. DATE() seems to work though.

B.

Jan 11 '06 #7

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

Similar topics

6
2228
by: Piotr Pietrowski | last post by:
Hello everybody, I have a *big* problem. I thought its not that big problem for you professionals... Anyway, I have a begin date which has 3 dropdown boxes (day/Month/Year). The same for the end date. So if somebody selects the begin date 13.12.2004 and the end date 19.12.2004
1
2876
by: Arjen | last post by:
Hi, How can I calculate the date 2 years ago? I get a problem with datetime minus int (year). Can someone help? Thanks!
6
5826
by: sreekandan | last post by:
Hi Now im doing one project to maint the login and logout time of the organization. So I need the VB codings to get the Current time and Date with detail. So kindly reply me anyone.
4
6319
stormrider
by: stormrider | last post by:
Hi all, I'm trying to implement a Perl structure. My small program will do the followings; Take the birth date of the user as input. (Month's will be input as strings.) Take the current time from the operating system. Then calculate and display the age of the user as; x years, x moonths and x days. I also want to add a day/month counter, so that the program will calculate and display the age of the user as;
2
3917
by: Drum2001 | last post by:
Hello, I am having isues with the following: I have two forms, a MAIN FORM with a SUB FORM: Within the MAIN FORM, I have an unbound textbox (Date Format) and a command button. Onload, the textbox defualts to Date(). The SUB FORM has a bound textbox (Date Format). I am trying to create the code for the command button to compare the
6
5682
by: Gilberto | last post by:
Hello I have a form where the user enters some pricing information. I need to store in the pricing table (fields time and date) the time and date WHEN the information was entered, so that later the user can print a report with these forms and can see EACH form at what time and date it was ORIGINALLY created/modified. So far i added two textbox to the form with time and date that show the CURRENT time and date, but when i try to print the...
2
4183
by: DThreadgill | last post by:
Not sure how to begin with this one. My table consists of: Branch# (number, double) EntryDate (datetime, mm/dd/yyyy hh:mm:ss am/pm) One branch can have many entry dates (i.e, Branch # 76 has 10 entry dates). I'm trying to show the most recent entry date & the previous entry date on a report. I know how to get the most recent entry date using Max. How would I get to the previous entry date? (Current is 2/14/2008 2:26:07 PM and...
1
1913
by: ShwetaJain | last post by:
Hi... I am able to get the type of the message as IPM.Appointmnet in the inbox but i am unable to get the due date, start date, for that appointment.... I am using MAPI in exchange server but i dont want Outlook MAPI to be used.... Thanks & Regards, Shweta
1
9780
by: smdmca | last post by:
I have Julian date, I want to convert it into date. Is there any function in MySql to convert Julian date to date eg- Julian Date- 2455116 Date - Oct - 12, 2009
0
8995
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
9558
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, 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...
0
9378
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...
1
9331
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,...
0
8250
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, 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...
0
6077
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
4608
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...
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2216
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.