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
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>...
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
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"!|/ ////////|
+----------------------+-----------------------------------+-----------+
"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
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"!|/ ////////|
>+----------------------+-----------------------------------+-----------+
--
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
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>...
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...
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.tm_mday = 1; ++lt.tm_mon;
ttime = mktime(<) - 60*60*24;
localtime_r(&ttime, <);
return lt.tm_mday;
}
--
William Warner
bill....@attws.com
hope this help
Philippe
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
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