"kaming" <gu***@guest.com> wrote in message

news:ck*********@imsp212.netvigator.com...

Dear all,

Do any one have idea how to obtain the exactly number of seconds in a
month with given month and year using DB2 given functions?

The formula is as simple as "No_of_days_for_a_month" * 60 * 60 * 24 .. but

It is a headache for me to find the No_of_days_for_a_month... in DB2

Thanks very much!

Look at the days() function in the SQL Reference for your platform.

The days() function expects a single date argument and returns the number of

days between Jan 1, 0001 and the date in the argument. While that is not

particularly interesting with respect to a single date, it gets a lot more

useful if you calculate the days() result on two dates and then subtract one

from the other: that tells you the number of days difference between the

two.

Therefore:

select days('2004-02-01') - days('2004-01-01')

from sysibm.sysdummy1

returns 31, the number of days in January, 2004.

By the same token:

select days('2004-03-01') -days('2004-02-01') as feb_2004,

days('2003-03-01') - days('2003-02-01') as feb_2003

from sysibm.sysdummy1;

returns:

FEB_2004 FEB_2003

29 28

In other words, Feb 2004 (which is a leap year) has 29 days while Feb 2003

(which is not a leap year) had 28 days.

Rhino