Need to get the number of days till today (starting from 1st Jan)

Hi Team,

I need to have a value in the variable which returns the number of days starting from 1st Jan.

Like suppose for example:
If the workflow is executed today (19th Aug 2019), then output is:-
= (Jan + Feb + Mar + Apr + May + Jun + Jul + (19 days of Aug)
= 31+28+31+30+31+30+31+19
= 231

Input = None. (since we can get the current date)
Output = 231.

NOTE:- Need to consider Leap year into this.
Please help me with this.

Thanks and Regards,

1 Like

Hope this would help you
Input will be like
DateTime.DaysInMonth(year, month) +…for all months + Now.Date

We need to convert to int32
Convert.ToInt32(DateTime.DaysInMonth(year, month))+…for all months + Convert.ToInt32(Now.Date)

So the steps involved are as follows
—use a assign activity like this
Inmonth = Convert.ToInt32(Now.ToString(“MM”))
Inyear = Convert.ToInt32(Now.ToString(“yyyy”))

Where Inmonth and Inyear is a int32 variable
—now use a while loop and pass the above variable as input with a Counter variable of type int32 with default value 0
Counter < Inmonth

—inside the loop use a assign activity
Innoofdays = Convert.ToInt32(DateTime.DaysInMonth(Inyear, Counter+1) + Innoofdays

Where Innoofdays is a int32 variable of default value 0

Next to this while loop use a assign activity like
Final_noofdays = Innoofdays + Convert.Toint32( Now.Date)

Hope these would help you resolve this
Cheers @hacky

Simply take the start date as Date.Parse(“01/01/” + now.Year.ToString)

and the end date as Date.Parse(now.ToShortDateString)

Then the difference will be (enddate - startdate + 1)

@hacky, Hope this helps

So just “day of the year” then?

You can use Now().DayOfYear



Excellent !!!
I knew I was missing out on some easy approach like this.
Thank you very much.

Although there is a twist here.

In my case, our financial year starts from 1st April. So need to have a variable as:
April + May + June + July (NOTE:- We need to ignore the 19 days of August).
So, 30 + 31+ 30 + 31 = 122…!
(So if we run the flow in August (any day of August) we need only days up to July)

How do we do this???

Do you always need to ignore the current month? As in, if you run this the 5th of September, do you then need to take August days into account?

And does it need to account for year rollover? As in, if you run this on Februay 1st next year (2020), should it count since April 1st 2019?


Never mind brother!

I had created a sheet in config file which will take care of it. So issue has been resolved.

Although just got an update from client that for any given month the days need to be considered upto previous month only.

so for 5th september, the days will be considered from april to august.

Also since the financial year starts from April, it ends in march.

Anyhow, the above config file approach satisfies all the concerns.

Thanks and Regards,

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.