Page 1 of 1

Find the last day of the month

Posted: Thu Aug 21, 2008 1:51 am
by kamesh_sk
Hi ,

Can anyone help me to find out the DS function to find the last day of the given month.i have one function called month.last from the built in transforms. so this will give me the internal format for the last day of the month whch i have supplied in the format yyyy-mm. Example: MONTH.LAST("1993-02") => 9191,
where 9191 is the internal representation of February 28, 1993...now i need a oconv function to convert this 9191 and get the date only.....can anyone help ...Thanks in advance

Posted: Thu Aug 21, 2008 1:55 am
by ArndW
Hint: Get the first day of the following month in internal format, then subtract one from it to get the last day of the prior month.

Posted: Thu Aug 21, 2008 2:28 am
by kamesh_sk
ArndW wrote:Hint: Get the first day of the following month in internal format, then subtract one from it to get the last day of the prior month. ...

Can you kindly explain this with an example

Posted: Thu Aug 21, 2008 2:48 am
by ArndW
The internal date of the last day of the month of February 2008 is

Code: Select all

ICONV('2008-03-01","D4-YMD[4,2,2]")-1
. You didn't specify if you wanted a full date, a day-of-the-week, a day-number in month or another format as output so I can't suggest any OCONV() function to use, but all the options are well-documented in the BASIC Programmer's Guide

Posted: Thu Aug 21, 2008 2:56 am
by kamesh_sk
ArndW wrote:The internal date of the last day of the month of February 2008 is

Code: Select all

ICONV('2008-03-01","D4-YMD[4,2,2]")-1
. You didn't specify if you wanted a full date, a day-of-the-week, a day-number in month or another format as output so I can't suggest any OCONV() function to use, but all the options are well-documented in the BASIC Programmer's Guide
sir,

My requirement is to check whether the date which i receive in a business date column is the last day of that particular month specified in the data.
For ex if i get a January month data , then the business date must be 31-01-2008..... so i need to check whether the given date is last date of the month jan and so on for other months also........so i was trying to figure out some solution for this.....can you kindly help

Posted: Thu Aug 21, 2008 3:32 am
by ArndW
If "OCONV(ICONV(YourDate,YourDateFormat)+1,'DD')=1" then YourDate is the last day of the month.

Posted: Thu Aug 21, 2008 5:18 am
by kamesh_sk
ArndW wrote:If "OCONV(ICONV(YourDate,YourDateFormat)+1,'DD')=1" then YourDate is the last day of the month. ...
Sir,

I tried this "OCONV(ICONV(YourDate,yyyymmdd)+1,'DD')=1" then the output is 1 and when i try with -1 then it is 30 ,,,and even when i change my month to Aug and with -1 it still gives 30...Afraid the code is not working properly......kindly help

Posted: Thu Aug 21, 2008 5:56 am
by thurmy34
Hi
You can try this YOURDATE=MONTH.LAST(YOURDATE).
The format of YOURDATE is DMY[2,2,4] in my case.

Posted: Thu Aug 21, 2008 6:52 am
by chulett
Close. The MONTH.LAST transform returns an internal date and expects the input as YYYY-MM. But you are correct that you can compare a date to this date and see if they match, as long as you've prepared both properly.

Posted: Thu Aug 21, 2008 7:00 am
by thurmy34
Hi
You are right Chulet , i missed a step in my job.
I convert a date to YOURDATE with

Code: Select all

 Oconv(de_table_pce.D_TRAITEMENT,"D/DMY[2,2,4]")
then i place this constraint to select the rows i want

Code: Select all

de_table_pce.D_TRAITEMENT=MONTH.LAST(YOURDATE [7,4]:'-':YOURDATE [4,2])