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

Date function in DB2 V8.1 for Z/OS

JAW
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?
Jun 27 '08 #1
4 6436
On May 6, 10:56 pm, JAW <jwill...@aglresources.comwrote:
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

Jun 27 '08 #2
Lennart wrote:
On May 6, 10:56 pm, JAW <jwill...@aglresources.comwrote:
>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
Jun 27 '08 #3
CURRENT DATE - (DAY(CURRENT DATE)-1) DAYS - 1 MONTH
or
CURRENT DATE - (DAYOFMONTH(CURRENT DATE)-1) DAYS - 1 MONTH
Jun 27 '08 #4
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
Jun 27 '08 #5

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

Similar topics

4
by: Funnyweb | last post by:
I have just notices that the date() function is not returning the correct date/time on my "server". I am running apache2 on my winxp pro laptop. My system clock is set to the correct date,...
3
by: Sharad Gupta | last post by:
Friends I need a date simple date function that would append the coming month value in my current month like monthname(month(date)) : gives me current month in string i need next month , a...
2
by: ltamisin | last post by:
Hi Im working on a Year(Date) function right now, the output of that function is this "2005", my question is how can i change the format into this "05" Function: Year(Date) Output: 2005...
8
by: Dennis M. Marks | last post by:
What is the maximum valid date range for the date(yyyy,mm,dd) function. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/ Replace domain.invalid with dcsi.net -----= Posted via...
5
by: Dennis M. Marks | last post by:
After reading section 15.9.1.1 the ECMAScript Language Specifications I see that the date range for the Date function is +/- 100,000,000 days from 01 Jan 1970. This is called an extrapolated...
6
by: bryan.seaton | last post by:
I have a delete statement that is not doing what I want it to do: Delete from LOG_TABLE where (DATE(LOG_TS)) < (DATE(CURRENT_DATE)- 21 DAYS); It is supposed to delete all records that are 21...
4
by: Christine | last post by:
I am having the strangest problem. I use the Date function in several of my forms and modules in an Access 2000 mdb. Lately, wherever in my code (in this one mdb) I use the Date function, it...
7
by: Christian Blackburn | last post by:
Hi Gang, VB6 has a command called Date and it would not to surprisingly return the date in the following ways: Date() = 9/10/2003 Date(now) = 9/10/2003 Date("8/12/2000 12:20PM") = 8/12/2000
4
by: Patrick McGuire | last post by:
I need to get the current date in vb .NET. In vba I always used the Date() function, and the help in .NET indicates that this function still exists, but I can't seem to find it. The Now()...
3
by: murch.alexander | last post by:
I made a simple public function to set and return a date value (see below). I have a number of queries that call up the function to get the "As Of Date," which is typically set to today's date....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.