Click here to Skip to main content
15,867,978 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone
i have created a word automation and email sending project (Sorry for my poor english) which automatically put the values according to the variables i have placed but for each week i have to renmae it like Report_OCT2022_First_Week

how to automate it like
var filename= Report_monthvariable+yearvariable_weekvariable

i know that we can use switch statement for the year variable but i don't know how to apply it here also for week

Please Help me to solve this

Thanks in advance

What I have tried:

used this for from and to date

var fromDate = fldFromDate.ToString("dd/MM/yyyy");
var toDate = fldToDate.ToString("dd/MM/yyyy");

var fldFromdateTodate = fromDate + " " + "to" + " " + toDate;
Posted
Updated 3-Nov-22 20:11pm

1 solution

To get the week number you can use: Calendar.GetWeekOfYear()
See: Calendar.GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek) Method (System.Globalization) | Microsoft Learn[^]

Here is some code from the CodeProject article Converting Numbers to Text in C#[^]
private static string ConvertDigitToString(int i)
        {
            switch (i)
            {
                case 0: return "";
                case 1: return "one";
                case 2: return "two";
                case 3: return "three";
                case 4: return "four";
                case 5: return "five";
                case 6: return "six";
                case 7: return "seven";
                case 8: return "eight";
                case 9: return "nine";
                default:
                    throw new IndexOutOfRangeException(String.Format("{0} not a digit",i));
            }
        }

        //assumes a number between 10 & 19
        private static string ConvertTeensToString(int n)
        {
            switch (n)
            {
                case 10: return "ten";
                case 11: return "eleven";
                case 12: return "twelve";
                case 13: return "thirteen";
                case 14: return "fourteen";
                case 15: return "fiveteen";
                case 16: return "sixteen";
                case 17: return "seventeen";
                case 18: return "eighteen";
                case 19: return "nineteen";
                default:
                    throw new IndexOutOfRangeException(String.Format("{0} not a teen", n));
            }
        }

        //assumes a number between 20 and 99
        private static string ConvertHighTensToString(int n)
        {
            int tensDigit = (int)( Math.Floor((double)n / 10.0));

            string tensStr;
            switch (tensDigit)
            {
                case 2: tensStr = "twenty"; break;
                case 3: tensStr = "thirty"; break;
                case 4: tensStr = "forty"; break;
                case 5: tensStr = "fifty"; break;
                case 6: tensStr = "sixty"; break;
                case 7: tensStr = "seventy"; break;
                case 8: tensStr = "eighty"; break;
                case 9: tensStr = "ninety"; break;
                default:
                    throw new IndexOutOfRangeException(String.Format("{0} not in range 20-99", n));
            }
            if (n % 10 == 0) return tensStr;
            string onesStr = ConvertDigitToString(n - tensDigit * 10);
            return tensStr + "-" + onesStr;
        }
 
Share this answer
 
v2
Comments
Manojkumar-dll 4-Nov-22 2:16am    
Thank you so much i'll try it out

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900