6/6/2012 3:03 PM  
Joined: 4/21/2010 Last visit: 2/25/2020 Posts: 21 Rating: (2) 
Hello to everybody, i must know number of actual week. For example: today is 06/06/2012 and we are in week 23. I find a solution by S7 algorit but i think there is an S7 block. Someone can show me this Siemens FB or FC, if it exist? Best regards

6/6/2012 3:17 PM  
Joined: 6/29/2011 Last visit: 5/26/2020 Posts: 127 Rating: (0) 
dear friend, Convert date and time of day to the DATE_AND_TIME format FC3: D_TOD_DT Extract the date from the DATE_AND_TIME format FC6: DT_DATE Extract the day of the week from the DATE_AND_TIME format FC7: DT_DAY Extract the time of day from the DATE_AND_TIME format FC8: DT_TOD try this 
param 

6/6/2012 3:33 PM  
Joined: 4/21/2010 Last visit: 2/25/2020 Posts: 21 Rating: (2) 
Thanks Paranthaman, but i want know the number of actual week of the year. Regards

6/6/2012 3:34 PM  
Posts: 2348 Rating: (246)

There is no standard function to define number of week, sorry. So if you have written your own algo  just use it :^) 
6/6/2012 3:37 PM  
Joined: 9/27/2006 Last visit: 8/6/2020 Posts: 9732 Rating: (2042)

Hello basket; I don't believe there is an application in Step 7 to calculate the number of the week. But Wikipedia has an illustratioon of the algorithm you would need to calculate it, and it does not seem too complex (if you prepare a lookup table for the year and use the information on the DT functions shown earlier): http://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_of_a_given_date Hope this helps, Daniel Chartier 
This contribution was helpful to1 thankful Users 
6/6/2012 3:49 PM  
Joined: 4/21/2010 Last visit: 2/25/2020 Posts: 21 Rating: (2) 
So i think i will you my alg........... its usefull but so complicate. Only for your information: for do it i must study calendar in 20 years. Try to immagine when you have an year like this with febrary of 29........ I enjoyed it you can understand. best regards to everybody

6/6/2012 4:07 PM  
Joined: 10/7/2005 Last visit: 8/7/2020 Posts: 2820 Rating: (947)

Hello Basket_78 the OSCAT library contains a "work_week" function which will calculate the week of the year in accordance with ISO8601. All Blocks are written in SCl,but should it interest you you go to http://www.oscat.de/downloadmanager.htmland downloadthe "oscat_basic_332_S7" library as well asthe english pdf documentation. 
Cheers 

This contribution was helpful to5 thankful Users 
6/6/2012 5:23 PM  
Joined: 1/17/2007 Last visit: 7/20/2020 Posts: 1448 Rating: (467) 
This little bit of code will do the trick for you I reckon . I have given it a quick test and it seems to work OK. [code] FUNCTION_BLOCK FB996 TITLE = 'Date of year' AUTHOR : Smiffy VAR_OUTPUT WEEK_NUM : INT; // Week number of year END_VAR VAR_TEMP DateAndTime : DT; // Date and time structure pointer to allow structure address below to be set DaT AT DateAndTime : STRUCT // Date and time structure to allow DT type to be disassembled Year : BYTE; // Current year (1990 to 2089  2 digits) Month : BYTE; // Current month (1 to 12) Day : BYTE; // Current day (1 to 31) Hour : BYTE; // Current hour (0 to 23) Minute : BYTE; // Current minute (0 to 59) Second : BYTE; // Current second (0 to 59) MSD : BYTE; // Most significant decade of current ms (0 to 99) LSD_Weekday : BYTE; // MSB = Least significant decade of current ms (0 to 9), LSB = Current weekday (1=Sunday to 7=Saturday) END_STRUCT; RetVal : INT; // Return Value of FC calls iYear : INT; // Integer value of year iMonth : INT; // Integer value of month Month_30 : INT; // Number of completed 30 day months Month_31 : INT; // Number of completed 31 day months Elapsed_Days : INT; // Number of completed elapsed days since start of year OrdinalDay : INT; // Current day number in current year END_VAR RetVal := READ_CLK(CDT := DateAndTime); IF RetVal >= 0 THEN // If READ_CLK Fc was successful iYear := BCD_TO_INT(DaT.Year); // Extract 2 digit year (yy) from DT and convert to integer format iMonth := BCD_TO_INT(DaT.Month); // Extract 2 digit month (mm) from DT and convert to integer format IF iMonth <> 1 THEN // If January has been passed (at least one complete month has elapsed) Month_31 := iMonth / 2; // Calculate the number of 31 day months passed (assuming alternating 31, 30 day month pattern) IF (iMonth MOD 2) = 0 THEN // If even month (assuming odd months = 31 days and even months = 30 days) Month_30 := Month_31  1; // Number of 30 day months passed is one less than the number of 31 days months passed ELSE // Otherwise (odd month) Month_30 := Month_31; // Number of 30 day months passed equals the number of 31 days months passed END_IF; Elapsed_Days := (Month_30 * 30) + (Month_31 * 31); // Calculate number of elapsed days in complete elapsed months IF iMonth <> 2 THEN // If the complete month of February has been passed IF (iYear MOD 4) = 0 THEN // If this year is a leap year... Elapsed_Days := Elapsed_Days  1; // ...then February has 29 days, so reduce already added 30 day month by 1 ELSE // ...Otherwise, it is not a leap year Elapsed_Days := Elapsed_Days  2; // ...so February has 28 days, so reduce already added 30 day month by 2 END_IF; END_IF; IF iMonth = 9 OR iMonth = 11 THEN // If month is September or November Elapsed_Days := Elapsed_Days + 1; // Take into account the July/August special case of non alternating 30, 31 month pattern END_IF; END_IF; OrdinalDay := Elapsed_Days + BCD_TO_INT(DaT.Day); // Add in the number of elapsed days in the current month WEEK_NUM := (OrdinalDay  DT_DAY(DateAndTime)  1 + 10) / 7; END_IF; END_FUNCTION_BLOCK [/code] 
Programming today is the race between software engineers building bigger and better idiot proof programs, and the universe producing bigger and better idiots. 

This contribution was helpful to2 thankful Users 
6/7/2012 8:11 AM  
Joined: 4/21/2010 Last visit: 2/25/2020 Posts: 21 Rating: (2) 
Thanks smiffy, i will try it and i thanks everybody for yours help. PS: i will download also the OSCAT_LIBRARY, usefull...... best regards

This contribution was helpful to2 thankful Users 
12/5/2017 5:50 PM  
Joined: 6/30/2017 Last visit: 4/12/2018 Posts: 1 Rating: (0) 
Hereś Smiffy's code impleented in TIA Portal; All variables are INT, exept for TMP_DTL, wich is "DTL" type. WEEK_NUM is an output variable.

This contribution was helpful to3 thankful Users 
Follow us on