Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


sysiq
  •  sysiq
  • Free support Topic Starter
2012-01-03T09:19:31Z
Is there somebody that can help me with creating a variable that gives me last week's number. We used {MATH(Subtract|Integer|{DATE(Week)}|1|#0)} last year, but this first week of the year that gives me 0 and not 52 like I want it to.
Sponsor
Forum information
Support
2012-01-03T09:29:52Z
Try using the .NET Code Task with this code:

using System;
using System.Globalization;

public class Test
{
 public static string GetPreviousWeek()
 {
	// Gets the Calendar instance associated with a CultureInfo.
	CultureInfo myCI = CultureInfo.CurrentCulture;
	Calendar myCal = myCI.Calendar;
	
	// Gets the DTFI properties required by GetWeekOfYear.
	CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
	DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
	
	return myCal.GetWeekOfYear(DateTime.Now.Subtract(new TimeSpan(7,0,0,0,0)), myCWR, myFirstDOW).ToString();
 }
}

Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
sysiq
  •  sysiq
  • Free support Topic Starter
2012-01-03T10:15:39Z
Thank you very much. But this gives me a compilation error:

"The type or namespace 'DayOfWeek' could not be found"
Support
2012-01-03T10:17:03Z
Include this in the top:

using System;
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
sysiq
  •  sysiq
  • Free support Topic Starter
2012-01-03T10:38:05Z
Works like a charm. Thank you Henrik.
Scroll to Top