# Get Specific Day Of Week From Popup Calendar

**URL:** <https://forum.inductiveautomation.com/t/get-specific-day-of-week-from-popup-calendar/9692>\
**Category:** Ignition\
**Created:** [February 11, 2015, 12:58pm UTC](https://forum.inductiveautomation.com/t/get-specific-day-of-week-from-popup-calendar/9692 "2015-02-11T12:58:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Automator59](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@Automator59](https://forum.inductiveautomation.com/u/Automator59)\
**Post date:** [February 11, 2015, 12:58pm UTC](https://forum.inductiveautomation.com/t/get-specific-day-of-week-from-popup-calendar/9692/1 "2015-02-11T12:58:00Z")

</div>

I need to capture the Sunday of a particular week selected with the Popup Calendar object and can’t find a script function to subtract days from the selected day. Basically, if a user clicks on Wednesday, February 11, 2015, I need to capture Sunday, February 8, 2015.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 11, 2015, 3:08pm UTC](https://forum.inductiveautomation.com/t/get-specific-day-of-week-from-popup-calendar/9692/2 "2015-02-11T15:08:47Z")

</div>

You can use java.util.Calendar to get the day of week:

Here’s a window to play with. Take note of the propertyChange script and custom properties of the calendar component. 🙂

[StartOfWeek\_2015-02-11\_1005.proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/cb447a3fe71efe8102383facb80ed0f992741978.proj) (9.74 KB)

EDIT: Sorry for the way short answer. I got pressed for time and I wanted to have something ready for you. 😆

The propertyChange script grabs the date, sets it to a java.util.Calendar object, and extracts the day of week. It then pops the result back out to the DOW custom property (minus 1-- more on that in a bit…).

`if event.propertyName=='date':
  from java.util import Calendar
  d=event.source.latchedDate
  c=Calendar.getInstance()
  c.setTime(d)
  event.source.DOW=c.get(Calendar.DAY_OF_WEEK)-1`  
The StartOfWeek custom property uses the expression:

`dateArithmetic({Root Container.Calendar.date},
               -({Root Container.Calendar.DOW}),
                "day")`  
Now, to explain the ‘minus 1’ thing. In the java.util.Calendar, Sunday has a value of one. If we left it that way it was, would actually be taking away one more day than needed. So we subtract on up front to give us a true offset to the day of week.

---

<div class="post-metadata">

**Author:** ![Automator59](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@Automator59](https://forum.inductiveautomation.com/u/Automator59)\
**Post date:** [February 11, 2015, 4:22pm UTC](https://forum.inductiveautomation.com/t/get-specific-day-of-week-from-popup-calendar/9692/3 "2015-02-11T16:22:48Z")

</div>

Thanks Jordan. I did go back and add a custom property and used an expression to capture it.

`switch({Root Container.Popup Calendar.DaySelected},
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
dateArithmetic({Root Container.Popup Calendar.date},-1,"day"),
dateArithmetic({Root Container.Popup Calendar.date},-2,"day"),
dateArithmetic({Root Container.Popup Calendar.date},-3,"day"),
dateArithmetic({Root Container.Popup Calendar.date},-4,"day"),
dateArithmetic({Root Container.Popup Calendar.date},-5,"day"),
dateArithmetic({Root Container.Popup Calendar.date},-6,"day"),
{Root Container.Popup Calendar.date})`

DaySelected is another custom property that is the day of week:

```auto
dateFormat({Root Container.Popup Calendar.date},"E")
```
