From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to find what the date was on Sunday

Solved!
Go to solution

Hi guys,

 

I am building a system where I am required to display results for the week so far, starting on Sunday. To do this I need to get a timestamp of what the date was at midnight on the last Sunday, and I am having trouble getting it right.

If possible I need it to work based off the system calendar, rather than doing some crazy 'if it's this month there are x no of days if the week spans two months' etc. (if that makes sense!)

 

I have been trying to use a timing control included in labview and changing the "Day of week" and "day of year" settings, but these do not seem to be making any difference to my timestamp as it is still taking the values from the "day of month" setting.

 

I was wondering if anyone on here can spot something I have missed?

 

I have attached a screenshot of the code I have tried to use, and a copy of the control I am using (it is a LabVIEW control that is included, but I have changed the name of it so I could have a copy in my local folder)

Download All
0 Kudos
Message 1 of 5
(2,716 Views)
Solution
Accepted by topic author BonbonBLou

The day of month has a special behavior which allows it to overflow and change the time. I don't think it was put in on purpose.

 

What you can do is to repeatedly subtract one day from now until you get to Sunday, like so (the d is a unit label):

 

Find Sunday.png


___________________
Try to take over the world!
Message 2 of 5
(2,707 Views)

Thank You!

 

I had to do a bit of modifying just to get it to midnight but this was basically just what I was looking for.

 

So simple - and yet it never even crossed my mind!

0 Kudos
Message 3 of 5
(2,694 Views)

You will probably also want to account for the case where the code is run on a Sunday.


___________________
Try to take over the world!
0 Kudos
Message 4 of 5
(2,684 Views)

Hi,

 

try this:

check.png

I separated calculation of last Sunday from setting time to midnight as I already have a subVI for the last part in my user.lib...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 5
(2,668 Views)