Page 1 of 1

DS-PX Day from Date

Posted: Wed Jan 20, 2010 3:53 am
by SP_ETL
Hi Folks

How to get lastday of the last week with referance to todays date(ie 20/0/2010).

Ex: suppose todays date is 05/01/2010 and I need last day of the last week(Ans should be 02/01/2010 ).

Posted: Wed Jan 20, 2010 4:26 am
by ArndW
With the "%e" or "%E" format of DateToString() you can get the numeric day-of-week for a given date, and with "%ddd" you can get the numeric day-of-year for that date. Subtract the day-of-week from the day-of-year and then reconvert to a date using StringToDate() and you have solved your problem.

Posted: Wed Jan 20, 2010 5:22 am
by ray.wurlod
What is your business rule for "last day of week"? In some countries weeks run from Sunday to Saturday, in other countries Monday to Sunday, etc. Without that knowledge no generic answer can be given.

Posted: Wed Jan 20, 2010 6:23 am
by ArndW
Ray - that is why I posted both %e and %E as those cover the 2 different commonly used first weekday definitions.

Posted: Wed Jan 20, 2010 8:03 am
by SP_ETL
ray.wurlod wrote:What is your business rule for "last day of week"? In some countries weeks run from Sunday to Saturday, in other countries Monday to Sunday, etc. Without that knowledge no generic answer can be give ...
Its 1st Case Sunday to Saturday