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.


rgepfert
2011-12-15T20:29:30Z
is there a way to get the quarter number (1, 2, 3, 4) from the current date? I tried using DateFormat(Q) and this did not work. I have to put a Quarter number in a filename and need a way to get the current or previous quarter number.
Sponsor
Forum information
ErikC
2011-12-19T09:12:08Z
Hi rgepfert,

What you can do is using a int variable for this. This variable will contain the quarter of the current month after a few steps:

Make 4 tasks to set a variable.
1. Set the quartervariable to: 1
2. Set the quartervariable to +1
3. Set the quartervariable to +1
4. Set the quartervariable to +1

So after running these tasks your quartervariable equals 4.
Now we are using conditions to prevent this from happening.

There are 3 conditions you have to make. One for task 2, 3 and 4:

Condition for task 2:
If the current month {DATEFORMAT(M)} is higher or equal than 4 continue else next task.

Condition for task 3:
If the current month {DATEFORMAT(M)} is higher or equal than 7 continue else next task.

Condition for task 4:
If the current month {DATEFORMAT(M)} is higher or equal than 10 continue else next task.

Now your quartervariable will contain the current quarter.

Good luck,
Erik
Uses Visualcron since 2006.
Support
2011-12-19T09:14:19Z
Just to let you know, you can also use the .NET Code execute Task with this code:


using System;

public class Test
{
	public static int GetQuarter()
	{
	return ((DateTime.Now.Month - 1) / 3) + 1 ;
	}
}

Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
ErikC
2011-12-19T09:42:25Z
Support wrote:

Just to let you know, you can also use the .NET Code



Much better!

Regards
Erik
Uses Visualcron since 2006.
Jon Tofte-Hansen
2017-02-13T14:22:45Z
I don't know what possibilities existed 5 years ago. In 8.2.4 you can do the following with variables:

Current quarter:
{MATH(Add|Double|{MATH(Divide|Double|{DATEFORMAT(MM)}|3|0.0)}|.2|0)}

Previous quarter:
{MATH(Add|Double|{MATH(Divide|Double|{DATENOWADD(Months|-3|MM)}|3|0.0)}|.2|0)}

Explanation:
-{DATEFORMAT(MM)} and {DATENOWADD(Months|-3|MM)} return the month number now and three months ago respectively
-The month number is divided by 3 to a double with one decimal - 0.0 (ex: 1 = 0.3, 12 = 4.0)
-The result is added the double .2 and then rounded to an integer by putting the last 0 (this method is used because no floor or ceil functions exist to my knowledge)

Note: locally I use "," as decimal mark in the add part. This works interactively in the variable section, but in the task I had to use "." as decimal mark to get it to work.
Scroll to Top