# Proposal to add a dayOfWeek() function to Processing

**URL:** <https://discourse.processing.org/t/proposal-to-add-a-dayofweek-function-to-processing/47016>\
**Category:** Processing\
**Created:** [August 25, 2025, 4:06am UTC](https://discourse.processing.org/t/proposal-to-add-a-dayofweek-function-to-processing/47016 "2025-08-25T04:06:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricRogerGarcia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ericrogergarcia/32/21029_2.png) [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)\
**Post date:** [August 25, 2025, 4:06am UTC](https://discourse.processing.org/t/proposal-to-add-a-dayofweek-function-to-processing/47016/1 "2025-08-25T04:06:08Z")

</div>

import java.util.Calendar;  
import java.util.GregorianCalendar;

int dayOfWeek() { // : 0 to 6, 0 is Sunday  
Calendar cal = new GregorianCalendar();  
int DAY\_OF\_WEEK=cal.get(cal.DAY\_OF\_WEEK);  
return DAY\_OF\_WEEK-1;  
}

---

<div class="post-metadata">

**Author:** ![sableraph](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sableraph/32/251_2.png) [@sableraph](https://discourse.processing.org/u/sableraph)\
**Post date:** [August 25, 2025, 1:20pm UTC](https://discourse.processing.org/t/proposal-to-add-a-dayofweek-function-to-processing/47016/2 "2025-08-25T13:20:03Z")

</div>

Hello @EricRogerGarcia,

Thanks for sharing your idea! For Processing feature requests, the best place is to open a [GitHub issue](https://github.com/processing/processing4/issues/new?template=3_feature-request.yml) so the team can review and track it there.

Raphaël

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 26, 2025, 2:18pm UTC](https://discourse.processing.org/t/proposal-to-add-a-dayofweek-function-to-processing/47016/3 "2025-08-26T14:18:12Z")

</div>

Hello @EricRogerGarcia,

I have a PDE tab (_pde file_ in sketch) for the utility functions I write and share these between sketches.

You can also create a _java file_ or a _jar file_ for use in other sketches directly in the sketch folder.

I just did the above and it is straightforward with a bit of research.  
There are plenty of resources for this out there.

I will leave the exploration of this with you.  
The fun part for me is the research and exploration!

Later consider creating a library for use with Processing that can be shared.

Examples:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/d/1/d16ab40cb8a9cb5f84ff51a9e69750940902de7e.png)

`:)`

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 27, 2025, 4:59pm UTC](https://discourse.processing.org/t/proposal-to-add-a-dayofweek-function-to-processing/47016/4 "2025-08-27T16:59:46Z")

</div>

Back in 2018 someone asked how to do this in Java and I suggested they looked at [Zeller’s congruence](https://en.wikipedia.org/wiki/Zeller%2527s_congruence).

It seemed like a fun task so I have implemented a [solution](https://editor.p5js.org/quark-js/sketches/rOUbwTmOA) and listed the code below.

You can confirm its accuracy [here](https://www.calculator.net/day-of-the-week-calculator.html?today=07%252F30%252F1966&x=Calculate).

**Note** the function expects the parameters in ‘day-moth-year’ order 👍 😀

```auto
/**
 * Calculate the day of the week for any valid date in the 
 * Gregorian Calendar.
 * 
 * author quark 27/8/2025
 */

function setup() {
    createCanvas(400, 400);
    testDayOfWeek(27, 8, 2025);
    testDayOfWeek(8, 5, 1945);
    testDayOfWeek(29, 7, 1969);
    testDayOfWeek(25, "dec", 2025);
    testDayOfWeek(30, 'july', 1966);
    testDayOfWeek(29, 'feb', 2001);
}

function testDayOfWeek(dd, mm, yyyy) {
    let day = dayOfWeek(dd, mm, yyyy);
    console.log(`${dd} / ${mm} / ${yyyy} Day: ${day.nbr} ${day.name}`);
}

/**
Calculates the day of the week
dd : day of the month 1 - 31 (depends on the month)
mm : month of year 1- 12 (January - December) or a case insensitive 
        string representing the month or the first few characters of
        the month e.g. 'sept' = September'
yyyy : the year including the century e.g. 1066

The actual parameters are tested to see if they represent a valid date.

The method returns an object with 2 fields
nbr : day of week (0 = Saturday ... 6 = Friday) or -1 if parameters do
        not represent a valid date
name : the full name of the day or "INVALID DATE"
*/
const dayOfWeek = function (dd, mm, yyyy) {
    const months = [
        "january", "febuary", "march", "april", "may,", "june",
        "july", "august", "september", "october", "november", "december"
    ];
    const daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    const dow = [
        "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"
    ];
    function isLeapYear(yyyy) {
        let b4 = yyyy % 4 == 0, b100 = yyyy % 100 == 0, b400 = yyyy % 400 == 0;
        return ((b4 & b400) | (b4 & !b100 & !b400)) == 1;
    }
    function getMonthNumber(mm) {
        if (typeof mm === "string") {
            mm = mm.trim().toLowerCase();
            return months.findIndex(m => m.startsWith(mm)) + 1;
        }
        return mm;
    }
    let day = { nbr: -1, name: "INVALID DATE" }
    if (yyyy < 0) return undefined;
    mm = getMonthNumber(mm);
    months[2] = isLeapYear(yyyy) ? 29 : 28;
    if (mm < 1 || mm > 12 || dd > months[mm]) return day;
    mm += mm <= 2 ? 12 : 0;
    let yy = yyyy % 100, cc = floor(yyyy / 100);
    let h = (dd + floor((13 * (mm + 1)) / 5) + yy + floor(yy / 4) +
        floor(cc / 4) - 2 * cc) % 7;
    day.nbr = h; day.name = dow[h];
    return day;
};

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 27, 2025, 5:28pm UTC](https://discourse.processing.org/t/proposal-to-add-a-dayofweek-function-to-processing/47016/5 "2025-08-27T17:28:25Z")

</div>

> [@quark](#):
>
> Back in 2018…

> [@Calendar - how can i get the first day of month by processing?](https://discourse.processing.org/t/calendar-how-can-i-get-the-first-day-of-month-by-processing/468/3):
>
> If you are interested in coding a solution using basic Java then have a look at [Zeller’s Congruence](https://en.wikipedia.org/wiki/Zeller%27s_congruence). It should be fun and not too difficult to implement slightly_smiling_face

> [@quark](#):
>
> and I suggested they looked at [Zeller’s congruence](https://en.wikipedia.org/wiki/Zeller%2527s_congruence).

[https://forum.processing.org/two/discussion/3350/getting-the-day-of-the-week-without-calendar](https://forum.processing.org/two/discussion/3350/getting-the-day-of-the-week-without-calendar)  
Another online version but for Java/Pjs:  
[http://Studio.ProcessingTogether.com/sp/pad/export/ro.9to4yV59zus7B](http://studio.processingtogether.com/sp/pad/export/ro.9to4yV59zus7B)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 28, 2025, 8:35pm UTC](https://discourse.processing.org/t/proposal-to-add-a-dayofweek-function-to-processing/47016/6 "2025-08-28T20:35:11Z")

</div>

> [@EricRogerGarcia](#):
>
> import java.util.Calendar;  
> import java.util.GregorianCalendar;

Hello again!

In my research I came across:

- The **`java.time`** package is the modern and recommended library for handling dates and times.
- The `java.util.Calendar` and `java.util.GregorianCalendar` classes are considered **legacy APIs** and should be avoided in new code.

`:)`

---

<div class="post-metadata">

**Author:** ![EricRogerGarcia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ericrogergarcia/32/21029_2.png) [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)\
**Post date:** [August 29, 2025, 9:17am UTC](https://discourse.processing.org/t/proposal-to-add-a-dayofweek-function-to-processing/47016/7 "2025-08-29T09:17:22Z")

</div>

yes, I saw that too but I haven’t yet managed to use the java.time package 🙃

Thank you for all the answers: I will look into it as soon as possible

(I have a little less time this week!).
