SCADA: How to get Week Number

5 Posts
3 Users
0 Likes
36 Views
(@r.buisson@arcinfo.com)
Posts: 0
New Member Guest
 

Do you know an easy way to get the Week Number in Scada?

 
Posted : 19/10/2012 6:53 pm
ED
 ED
(@e-duvalarcinfo-com)
Posts: 138
Estimable Member
 

Hi Romain
I found this and that should be Ok to code in SCADA BASIC but I did not check.

If you assume that:

  • week 1 starts on January 1st of a given year
  • week n+1 starts 7 days after week n

For an arbitrary day (1..31) of a given month (1..12) and year, the SWN can be calculated by:

SWN( y, m, d ) = 1 + ( DP( y, m ) + d-1 ) / 7

where DP ("Days Passed") is given by:

DP( y, 1 ) = 0
DP( y, m+1 ) = DP( y, m ) + ML( y, m )
and ML ("Month Length") is defined as:

ML( y, 1 ) = 31
ML( y, 2 ) = 28 + LEAP( y )
ML( y, 3 ) = 31
ML( y, 4 ) = 30
ML( y, 5 ) = 31
ML( y, 6 ) = 30
ML( y, 7 ) = 31
ML( y, 8 ) = 31
ML( y, 9 ) = 30
ML( y, 10 ) = 31
ML( y, 11 ) = 30
ML( y, 12 ) = 31
and LEAP( y ) is defined as:

LEAP( y ) = ( y % 4 == 0 ) && ( ( y % 100 != 0 ) || ( y % 400 == 0 ) )

 
Posted : 19/10/2012 8:01 pm
n.kunzer
(@n-kunzerarcinfo-com)
Posts: 1236
Member Moderator
 

I vote for the VBA Format instruction

Sub test()

Dim sWeek As String

sWeek = Format(Now, "ww")

End Sub

Just take care on one point: the Format instruction has the following syntax:
For­mat(expres­sion [,for­mat [,first­day­ofweek [,first­weeko­fyear]]])

So, you can keep the first day of week and first week of year by default or use your own:

The first­day­ofweek argu­ment has these settings:

Con­stant Value Descrip­tion
vbUs­eSys­tem 0 Use NLS API setting.
vbSun­day 1 Sun­day (default)
vbMon­day 2 Mon­day
vbTues­day 3 Tues­day
vbWednes­day 4 Wednes­day
vbThurs­day 5 Thurs­day
vbFri­day 6 Fri­day
vbSat­ur­day 7 Sat­ur­day

The first­weeko­fyear argu­ment has these settings:

Con­stant Value Descrip­tion
vbUs­eSys­tem 0 Use NLS API setting.
vbFirstJan1 1 Start with week in which Jan­u­ary 1 occurs (default).
vbFirst­Four­Days 2 Start with the first week that has at least four days in the year.
vbFirst­Full­Week 3 Start with the first full week of the year.

 
Posted : 22/10/2012 8:42 am
ED
 ED
(@e-duvalarcinfo-com)
Posts: 138
Estimable Member
 

Ahhh Mr VBA...
Romain asked specificaly for a SCADA BASIC solution.
But in VBA of course this is easier 😛

 
Posted : 22/10/2012 2:09 pm
(@r.buisson@arcinfo.com)
Posts: 31
Eminent Member Guest
 

Thanks Manu I'll try it.

Thanks Niko, but in VBA there is a lot of source on the net, so it will be easier to find a solution 🙂

 
Posted : 23/10/2012 9:18 am