If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DATE: valid expression

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-03-03, 07:59
stefanB stefanB is offline
Registered User
 
Join Date: Oct 2003
Posts: 18
Arrow DATE: valid expression

Hi all,

Is this actually a valid expression for DB v 7.2?

SELECT TABLE.ATTR1
FROM TABLE
WHERE
CURRENT DATE - 1 MONTH <= LAST_DAY(TABLE.ATTR2)

ATTR2 is a DATE-column...

Appreciate everyones help!!!

Thanks in Advance,

S.B.
Reply With Quote
  #2 (permalink)  
Old 11-03-03, 09:26
chimes1967 chimes1967 is offline
Registered User
 
Join Date: Feb 2003
Posts: 9
Re: DATE: valid expression

CURRENT DATE - 1 MONTH <= (attr2 + 1 MONTH) - day(attr2 + 1 month) days
works, last_day is an oracle function, not a db2. The above should do the same thing though.


Cliff

Quote:
Originally posted by stefanB
Hi all,

Is this actually a valid expression for DB v 7.2?

SELECT TABLE.ATTR1
FROM TABLE
WHERE
CURRENT DATE - 1 MONTH <= LAST_DAY(TABLE.ATTR2)

ATTR2 is a DATE-column...

Appreciate everyones help!!!

Thanks in Advance,

S.B.
Reply With Quote
  #3 (permalink)  
Old 11-03-03, 10:40
stefanB stefanB is offline
Registered User
 
Join Date: Oct 2003
Posts: 18
Re: DATE: valid expression

Hi,

thanks! That's it!

By the way... Are this two alternative expressions valid?

CURRENT DATE - 1 MONTH <= (attr2 + 1 MONTH) - day(attr2) days

CURRENT DATE - 1 MONTH <= (attr2 + 1 MONTH) - (1 DAY)


Thanks in Advance,

S.B.

Quote:
Originally posted by chimes1967
CURRENT DATE - 1 MONTH <= (attr2 + 1 MONTH) - day(attr2 + 1 month) days
works, last_day is an oracle function, not a db2. The above should do the same thing though.


Cliff
Reply With Quote
  #4 (permalink)  
Old 11-03-03, 11:10
chimes1967 chimes1967 is offline
Registered User
 
Join Date: Feb 2003
Posts: 9
Re: DATE: valid expression

They are valid sql statements, but they will not get you the last day of the month.

Quote:
Originally posted by stefanB
Hi,

thanks! That's it!

By the way... Are this two alternative expressions valid?

CURRENT DATE - 1 MONTH <= (attr2 + 1 MONTH) - day(attr2) days

CURRENT DATE - 1 MONTH <= (attr2 + 1 MONTH) - (1 DAY)


Thanks in Advance,

S.B.
Reply With Quote
  #5 (permalink)  
Old 11-04-03, 02:17
stefanB stefanB is offline
Registered User
 
Join Date: Oct 2003
Posts: 18
Re: DATE: valid expression

Hi,

thanks for you reply!
AFAIK LAST_DAY is a scalar function only for DB2 Universal Database for OS/390 and z/OS.
I found this SQL statement on SearchDatabase, that calculates the last day of a month too:

(DATE('02/01/2000') + 1 MONTH) - DAY(DATE('02/01/2000')) DAYS

with the result "02/29/2000".

Unfortunately, I sill don't have a DB2-account, so I cann't prove, if the statements provide the same result.
The only drifference seems to be "+ 1 MONTH" in the last part of the expression...

S.B.

Quote:
Originally posted by chimes1967
They are valid sql statements, but they will not get you the last day of the month.
Reply With Quote
  #6 (permalink)  
Old 11-04-03, 10:44
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
If you take the first day of the following month that you want and subtract 1 day, then you will get the last day of the month.

For last day of February 2000, take March 01, 2000 and subtract 1 day:

select date('2000-03-01') - 1 day, from employee

yields

02/29/2000
Reply With Quote
  #7 (permalink)  
Old 11-04-03, 11:40
stefanB stefanB is offline
Registered User
 
Join Date: Oct 2003
Posts: 18
Hi,

yes, but how do I get the first day of the following month?
Thanks in Advance,
S.B.
Quote:
Originally posted by Marcus_A
If you take the first day of the following month that you want and subtract 1 day, then you will get the last day of the month.

For last day of February 2000, take March 01, 2000 and subtract 1 day:

select date('2000-03-01') - 1 day, from employee

yields

02/29/2000
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On