Page 1 of 1

MONTH & YEAR FROM DATE

Posted: Thu Jan 06, 2011 4:35 am
by ajithaselvan
Hi,
Pls let me know what is function to be used to get
only month & year from date. Format is below

Input: YYYY-MM-DD
Output: MM-YY



Thanks & Regards,

Posted: Thu Jan 06, 2011 4:53 am
by dr.murthy
Use substring function

Posted: Thu Jan 06, 2011 4:59 am
by ajithaselvan
Thanks Murthy

Posted: Thu Jan 06, 2011 6:23 am
by chulett
This 'date' field, what actual data type are we talking about? The current answer is fine if you are talking about a string but it's not correct for an actual 'date date'.

Posted: Thu Jan 06, 2011 6:53 am
by ajithaselvan
Hi chulett,
What would be the correct ans if the data type is date?





Thanks & Regards,

Posted: Thu Jan 06, 2011 8:09 am
by Ravi.K
you have to use "DateToString" function to define correct date mask.

Posted: Thu Jan 06, 2011 3:38 pm
by ray.wurlod

Code: Select all

Right("00":MonthFromDate(InLink.TheDate) : "-" : Right(YearFromDate(InLink.TheDate),2)

Posted: Thu Jan 06, 2011 11:33 pm
by dsa
ray.wurlod wrote:

Code: Select all

Right("00":MonthFromDate(InLink.TheDate) : "-" : Right(YearFromDate(InLink.TheDate),2)
...
Ray,

Should we use:

Right("00":MonthFromDate(InLink.TheDate),2) : "-" : Right(YearFromDate(InLink.TheDate),2)

??? as the requirement is MM-YY?

Posted: Fri Jan 07, 2011 12:33 am
by ray.wurlod
Can you please advise what you think is wrong with the expression I gave?

Have you tried it?

Posted: Fri Jan 07, 2011 8:04 am
by chulett
Took me a minute but the difference is the "2" that was added at the end of this part for the month:

Code: Select all

Right("00":MonthFromDate(InLink.TheDate),2)

Posted: Fri Jan 07, 2011 4:27 pm
by ray.wurlod
:oops:

Code: Select all

Right("00":MonthFromDate(InLink.TheDate), 2) : "-" : Right(YearFromDate(InLink.TheDate), 2)