day of the week

Other discussions about CSPro
Forum rules
New release: CSPro 8.0
Post Reply
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

day of the week

Post by AriSilva »

Hi,
Is there a funcion (or algorithm) that returns the day of the week for a particular date (yyyymmdd)?
Best
Ari
Best
Ari
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: day of the week

Post 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.
Post Reply