Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Last day of month..

439 views
Skip to first unread message

SUNIL S. SINGH

unread,
Sep 20, 1998, 3:00:00 AM9/20/98
to

Hi All !!

Is there any function or technique to find last day of month
ie 29 or 28 or 30 or 31 for a particular date(dd/mm/yy)

Any Help IS appreciated ...

Thanks.
Sunil

David K. Killough

unread,
Sep 20, 1998, 3:00:00 AM9/20/98
to
Something like this (in 4gl):

DEFINE pv_date DATE # passed date (say 12/14/98)
DEFINE lv_eom DATE # local working date / final result: End of Month
(12/31/98)
LET lv_eom = MONTH(TODAY),"/01/",YEAR(TODAY) # sets first day this month
(12/1/98)
LET lv_eom = lv_eom + 35 # somewhere in next month (01/04/98)
LET lv_eom = MONTH(lv_eom),"/01/",YEAR(lv_eom) # first day next month
(01/01/98)
LET lv_eom = lv_eom - 1 # one day earlier is end of month for pv_date
(12/31/98)
RETURN lv_eom

There is probably a better way, and my code probably has some mistake, but
the general idea is that the first day of the next month less one is the end
of the month for any date.

Dave Killough

SUNIL S. SINGH wrote in message <6u2o5c$bmr$1...@news.xmission.com>...

Octav Chiriac

unread,
Sep 21, 1998, 3:00:00 AM9/21/98
to

SUNIL S. SINGH wrote:
>
>Hi All !!
>
>Is there any function or technique to find last day of month
>ie 29 or 28 or 30 or 31 for a particular date(dd/mm/yy)
>
Let's say our date is m_date:

DAY(MDY(MONTH(m_date), 1, YEAR(m_date)) + 1 UNITS MONTH) - 1 UNITS DAY)

Hope it helps,
Octav


--
Octav Chiriac Phone: (373) 2 21 20 96
NetInfo S.R.L. Fax: (373) 2 21 20 96
Chisinau (373) 2 24 00 83
Moldova, Republic of mailto:c...@netinfo-moldova.com

Mark D. Stock

unread,
Sep 21, 1998, 3:00:00 AM9/21/98
to

SUNIL S. SINGH wrote:
>
> Hi All !!
>
> Is there any function or technique to find last day of month
> ie 29 or 28 or 30 or 31 for a particular date(dd/mm/yy)

Try:

SELECT DAY(MDY(MONTH(TODAY)+1,1,YEAR(TODAY))-1)
FROM systables
WHERE tabid = 1

Where 'a particular date' is TODAY.

Cheers,
--
Mark.

+----------------------------------------------------------+-----------+
|Mark D. Stock - Informix SA http://www.informix.com |//////// /|
|mailto:mds...@informix.com http://www.informix.com/idn |///// / //|
|http://www.iiug.org +-----------------------------------+//// / ///|
| Tel: +27 11 807 0313 |If it's slow, the users complain. |/// / ////|
| Fax: +27 11 807 2594 |If it's fast, the users keep quiet.|// / /////|
|Cell: +27 83 250 2325 |Therefore, "No news: travels fast"!|/ ////////|
+----------------------+-----------------------------------+-----------+

GAC

unread,
Sep 21, 1998, 3:00:00 AM9/21/98
to

According to the ANSI text book on SQL I'm studying you could try:

"SQL> SELECT ENDDATE, LAST_DAY(ENDDATE)
2 FROM PROJECT;"

LAST_DAY being the function that finds the last day of the month.
As always check your implementation.


>>SUNIL S. SINGH wrote:
>>
>>Hi All !!
>>
>>Is there any function or technique to find last day of month
>>ie 29 or 28 or 30 or 31 for a particular date(dd/mm/yy)
>>

>Octav Chiriac wrote:
>Let's say our date is m_date:

>DAY(MDY(MONTH(m_date), 1, YEAR(m_date)) + 1 UNITS MONTH) - 1 >UNITS DAY)


-------
Stan Hixon
Postcript-DBA
GAC-Atlanta
hix...@cgprinting.com


Octav Chiriac

unread,
Sep 21, 1998, 3:00:00 AM9/21/98
to

Mark D. Stock wrote:
>SUNIL S. SINGH wrote:
>>
>> Hi All !!
>>
>> Is there any function or technique to find last day of month
>> ie 29 or 28 or 30 or 31 for a particular date(dd/mm/yy)
>
>Try:
>
>SELECT DAY(MDY(MONTH(TODAY)+1,1,YEAR(TODAY))-1)
>FROM systables
>WHERE tabid = 1
>

OOPS, WRONG, WRONG !!!!

What is the result for december dates ?

@informix.com ??? To :-) OR :-( ???

Bye,
Octav

>|Mark D. Stock - Informix SA http://www.informix.com |//////// /|
>|mailto:mds...@informix.com http://www.informix.com/idn |///// / //|
>|http://www.iiug.org +-----------------------------------+//// / ///|
>| Tel: +27 11 807 0313 |If it's slow, the users complain. |/// / ////|
>| Fax: +27 11 807 2594 |If it's fast, the users keep quiet.|// / /////|
>|Cell: +27 83 250 2325 |Therefore, "No news: travels fast"!|/ ////////|
>+----------------------+-----------------------------------+-----------+

--

Sunil Thakkar

unread,
Sep 21, 1998, 3:00:00 AM9/21/98
to

Last day of the month.

Check for the correct syntex but the logic works:

Function last_day_m(month, year) returning date;

let dd = 28
let xdate = dd + mm + yyyy
whenever error continue ;
for i = 1 to 3
dd = dd + 1 ;
xdate = dd + mm + yyyy ;
if xdate is invalid
exit for
end if
next i
dd = dd + 1
xdate = dd + mm + yyyy

return xdate

end function;

Thanks,
Sunil.

----Original Message Follows----
Subject: Re: Last day of month..
To: mds...@informix.com
Date: Mon, 21 Sep 1998 17:39:41 +0300 (EETDST)
From: Octav Chiriac <c...@netinfo-moldova.com>
Cc: inform...@iiug.org
Reply-to: c...@netinfo-moldova.com

OOPS, WRONG, WRONG !!!!

Bye,
Octav

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

Chuck Ludwigsen

unread,
Sep 22, 1998, 3:00:00 AM9/22/98
to
ummm, try...

MDY(MONTH(in_date), 1, YEAR(in_date)) + 1 UNITS MONTH - 1 UNITS DAY;

returns a date value of the last day of the month for the month of
"in_date".

Sunil Thakkar <sun...@hotmail.com> wrote in article
<6u654h$qa0$1...@news.xmission.com>...

Louis DeLongchamp

unread,
Sep 22, 1998, 3:00:00 AM9/22/98
to
>SUNIL S. SINGH wrote:
>
>Hi All !!
>
>Is there any function or technique to find last day of month
>ie 29 or 28 or 30 or 31 for a particular date(dd/mm/yy)
>

Here is the function that will do it! The function takes
your date and returns the last day ie. 28, 29, 30 or 31.

function fn_leap(fndate)
define
fndate date,
j, k smallint
let j = month(fndate)
if j = 4 or j = 6 or j = 9 or j = 11 then return 30 end if
if j <> 2 then return 31 end if
let k = year(fndate)
if k mod 100 = 0 then
if k mod 400 = 0 then return 29
else return 28 end if
else
if k mod 4 = 0 then return 29 end if
end if
return 28
end function


loudelon...

William Warner

unread,
Sep 22, 1998, 3:00:00 AM9/22/98
to Louis DeLongchamp
Louis DeLongchamp wrote:
>
> >SUNIL S. SINGH wrote:
> >
> >Hi All !!
> >
> >Is there any function or technique to find last day of month
> >ie 29 or 28 or 30 or 31 for a particular date(dd/mm/yy)
> >
>

You don't know how many days are in a month, but you know that the first
day of every month is numbered with a 1. To get the number of the last
day in a month, subtract one day from the first day of next month.

In unix C:

unsigned int lastday(const time_t t) {

/*
* compute the day before the first day of next month
*/

struct tm lt;
unsigned int lday;
time_t ttime;

localtime_r(&t, &lt);
lt.tm_mday = 1; ++lt.tm_mon;
ttime = mktime(&lt) - 60*60*24;
localtime_r(&ttime, &lt);
return lt.tm_mday;
}

--
William Warner
bill....@attws.com

Ph. Chantry

unread,
Sep 23, 1998, 3:00:00 AM9/23/98
to
if X is your date,
Y=DAY(MDY(MONTH(X),1,YEAR(X)) + 1 UNITS MONTH - 1 UNITS DAY)
gives you the last day of the month

hope this help
Philippe


June Tong

unread,
Sep 30, 1998, 3:00:00 AM9/30/98
to
Rudolf Fernandes wrote:
>In SQL, you could use the following
>
>SELECT
> DAY(MDY( MONTH(MDY(MONTH(your_date),1,YEAR(your_date))+32) , 1,
> YEAR(MDY(MONTH(your_date),1,YEAR(your_date))+32) ) - 1)
>FROM systables
>WHERE TABNAME = 'systables';
>
>
>Explanation :
>
>1. mdy(month(your_date), 1, year(your_date)) + 32
> always takes you into the next month

Not if you're on the last day of a month. Then this will take you
forward two months. Also if you're on the 30th of any month besides
July and December, or on the 28th or 29th of January. No, I don't think
this method is going to work.

June
--
jun...@hotmail.com
Lost in the wilds of Palo Alto, living on Peanut M&M's

Degtearyov M.V.

unread,
Oct 1, 1998, 3:00:00 AM10/1/98
to

Try this:

date(mdy(month(your_date), 1, year(your_date)) +1 units month - 1 units day)

Using of date() is essential if you want to get DATE instead
DATETIME YEAR TO DAY.

--------------
Mike Degtyarev

d...@netinfo-moldova.com

0 new messages