day of the week

Other discussions about CSPro
AriSilva
Posts: 183
Joined: July 22nd, 2016, 3:55 pm

day of the week

Postby AriSilva » January 22nd, 2019, 9:56 am

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: 1743
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: day of the week

Postby josh » January 22nd, 2019, 10:42 am

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.


Return to “Other”