Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-07-2008, 10:15 AM
JAW
 
Posts: n/a
Default Date function in DB2 V8.1 for Z/OS

I need to get the first day of the previous month in a query.

I thought CURRENT DATE and DAYOFMONTH would allow me to da it but it
is noe

WHERE DTXL >= 1st day of previous month


Anyone got a good idea?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-07-2008, 10:15 AM
Lennart
 
Posts: n/a
Default Re: Date function in DB2 V8.1 for Z/OS

On May 6, 10:56 pm, JAW <jwill...@aglresources.com> wrote:
> I need to get the first day of the previous month in a query.
>
> I thought CURRENT DATE and DAYOFMONTH would allow me to da it but it
> is noe
>
> WHERE DTXL >= 1st day of previous month
>
> Anyone got a good idea?


I'm not familiar with DB2 for Z/OS but do you mean something like:

[lelle@53dbd181]$ db2 "values current_date - 1 month -
day(current_date) days + 1 day"

1
----------
04/01/2008

1 record(s) selected.

/Lennart

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-07-2008, 10:15 AM
The Boss
 
Posts: n/a
Default Re: Date function in DB2 V8.1 for Z/OS

Lennart wrote:
> On May 6, 10:56 pm, JAW <jwill...@aglresources.com> wrote:
>> I need to get the first day of the previous month in a query.
>>
>> I thought CURRENT DATE and DAYOFMONTH would allow me to da it but it
>> is noe
>>
>> WHERE DTXL >= 1st day of previous month
>>
>> Anyone got a good idea?

>
> I'm not familiar with DB2 for Z/OS but do you mean something like:
>
> [lelle@53dbd181]$ db2 "values current_date - 1 month -
> day(current_date) days + 1 day"
>
> 1
> ----------
> 04/01/2008
>
> 1 record(s) selected.
>
> /Lennart


I'm not sure your solution will work in all cases.
How about current_date values like:
05/31/2008
or
03/29/2008 vs. 03/30/2008 vs. 03/31/2008

I think it is more safe to first calculate the first day of the current
month and subtract a month afterwards:

SELECT (CURRENT DATE - (DAYOFMONTH(CURRENT DATE) - 1) DAYS) - 1 MONTH
FROM SYSIBM.SYSDUMMY1

Cheers!

--
Jeroen


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-07-2008, 10:15 AM
Tonkuma
 
Posts: n/a
Default Re: Date function in DB2 V8.1 for Z/OS

CURRENT DATE - (DAY(CURRENT DATE)-1) DAYS - 1 MONTH
or
CURRENT DATE - (DAYOFMONTH(CURRENT DATE)-1) DAYS - 1 MONTH
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-07-2008, 10:15 AM
Tonkuma
 
Posts: n/a
Default Re: Date function in DB2 V8.1 for Z/OS

It would be better to use DAY instead of DAYOFMONTH for portability.

Article:
The SQL Reference for Cross-Platform Development
http://www-128.ibm.com/developerwork...206sqlref.html

PDF Manual:
SQL Reference for Cross-Platform Development Version 3
(DB2 for: z/OS V9, iSeries V5R4, LUW V9)
ftp://ftp.software.ibm.com/ps/produc...S/cpsqlrv3.pdf
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

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



All times are GMT. The time now is 08:39 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62