Search code examples
rpa

How do i get current month name , week number and starting week date and ending week date in vb scipt?


i have to write vb script to get current month name, week number, week starting date and ending date for eg: Feb_3rdWeek_11th_to_17th in this format.

this VB script file i have to call in RPA tool.


Solution

  • enter image description here

    DateTime dt=DateTime.Now;
    Output_Format=dt.ToString("MMMM");
    temp=dt.DayOfWeek-DayOfWeek.Monday;
    startdate=dt.AddDays(-(int)temp);
    enddate=dt.AddDays((int)(7-temp));
    CultureInfo ci = CultureInfo.CurrentCulture; 
    int weekNumber = ci.Calendar.GetWeekOfYear(dt, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); 
    weeknumber= weekNumber;

    The above code is written in c#, it serves your purpose. except it returns the week number of the year instead of the month. with the values at your hand you can format it the way you wanted.