function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
subaasubaa 

How can I find day value (eg. Sunday) from Datetime API

Hi,

 

How can I find day value (eg. Sunday) from Datetime API. Or do we have any other API to find this?

 

Regards,

SuBaa

mroarkmroark

You can use Sakamoto's algorithm (http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week#Sakamoto.27s_algorithm)

 

From Wikipedia:

 

 int dow(int y, int m, int d) {
static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= m < 3;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}

In the above, y, m and d are, respectively the year (e.g., 1988), month (1-12) and day of the month (1-31).  The function returns 0 = Sunday, 1 = Monday, etc.