I need to extract some data in a website every week. Basically I need the data for 1) current month / year (e.g. May / 2020), 2) last month / year (e.g. April / 2020), 3) last last month / year (e.g. March / 2020).
Currently format:
(1) current month / year: Now.ToString(“MMMM”) + " / " + Now.ToString(“yyyy”)
(2) last month / year: DateTime.Now.AddMonths(-1).ToString(“MMMM”)+" / "+Now.ToString(“yyyy”)
(3) last last month / year: I am still looking for solutions
But as I am looking for the solutions, I found a problem for (2) and (3). If I am to Now.ToString(“yyyy”), I may encounter problems when the current month is, for example, January 2021. In this case, I suppose the output result for (2) would be “December / 2021” instead of “December / 2020”? How can I solve this problem so that the year will change accordingly? And how should the (3) be coded? Thank you!!
Thank you! That should work well. I just have one question: can thisMonth.ToString(“MMMMM”) be replaced with thisMonth.ToString(“MMMM”)? Any difference between MMMMM & MMMM?
Thank you. Can you confirm my understanding that a total of 6 variables + 6 Assign activities are required in order to perform the tasks (i.e. generating 1) the current & last 2 months / year and 2) the last day of the current & last 2 months)?
Yes, you are right. If I were to add something, first perhaps we should assign first and last day variables, next month and year string variable using them, as the following.