Page 1 of 1

day of the week

Posted: January 22nd, 2019, 9:56 am
by AriSilva
Hi,
Is there a funcion (or algorithm) that returns the day of the week for a particular date (yyyymmdd)?
Best
Ari

Re: day of the week

Posted: January 22nd, 2019, 10:42 am
by josh
In CSPro 7.1 we added the timstring function that can do this: http://www.csprousers.org/help/CSPro/ti ... ction.html

In earlier versions of CSPro you could write a function like this to do it:
// Compute day of week from date
// Returns 1 for Sunday, 2 for Monday..
function dayOfWeek(yyyymmdd)
    numeric referenceDay = 20170827; // This was be a Sunday
    numeric diff = datediff(referenceDay, yyyymmdd, "d");
    dayOfWeek = diff % 7 + 1;
end;
The above function is from the Labor Force Survey example in the CSPro examples folder.