First Day of the current week on Client startup

I am racking my brains trying to figure out to automatically set a date on a calendar component to the first day of the current week. This is my chart, it displays weekly historical CIP data in a chart starting on a Sunday of the selected week from the calendar component. Issue I have, each time the clients shut down, the calendar start date reverts back to the date when the project was last saved.

I am using a client startup script to capture the time & date the project was launched and then want to set the calendar to the 1st day of the week of the current week. Just cant figure a ‘smart’ way to calculate what that date should be.
So far I am thinking of a look up table for the next few years, that has the day # of the first Sunday of the selected year and use math voodoo to figure out when the closest Sunday is.

I have to do this using V7.7.8

[attachment=0]2016-11-28 17_46_43-Eview - Ignition Designer.png[/attachment]

Could use dateExtract or system.date.getDayOfWeek to get the (0 indexed) day of the week, then date arithmetic to back that into a Sunday?

Thanks,
I will use the date extract and voodoo math. I am using V7.7.8 and system.date.get is for V7.8

This is easy to do just using Python.

http://stackoverflow.com/questions/39441639/getting-the-date-of-the-first-day-of-the-week

Also I would recommend just grabbing the current datetime when the window is opened. In my experience some users will open a client and not close it for days or even weeks so if you get the current date when someone opens the project it may no longer be accurate when they go to use your calendar control.

Edit: Some adjustment to the code in the link was necessary to make this work >

[code]from datetime import datetime, timedelta

sunday = datetime.today() - timedelta(days=datetime.today().isoweekday() % 7)
print sunday[/code]

Remember that if your clients use different locales, the first day of the week isn’t always Sunday. If you need to deal with multiple locales, this Stack Overflow question can help. (You’ll need to import Calendar from Java.)

[quote=“JGJohnson”]This is easy to do just using Python.

http://stackoverflow.com/questions/39441639/getting-the-date-of-the-first-day-of-the-week

Also I would recommend just grabbing the current datetime when the window is opened. In my experience some users will open a client and not close it for days or even weeks so if you get the current date when someone opens the project it may no longer be accurate when they go to use your calendar control.

Edit: Some adjustment to the code in the link was necessary to make this work >

[code]from datetime import datetime, timedelta

sunday = datetime.today() - timedelta(days=datetime.today().isoweekday() % 7)
print sunday[/code][/quote]

This is what I ended up doing, had to use the date.today() as datetime.today() set the time to the current time. Date.today() sets the time to 00:00:00.
Also even though the calendar component was bound to the custom property ‘opendate’, the calendar did not update when the window first opened. I had to write to the calendar’s date property.

[attachment=0]2016-12-04 11_02_30-Eview - Ignition Designer.png[/attachment]