Get date of first monday coming month

I need to get the date (formatted as “yyyy-mm-dd”) of the first Monday in the coming month based on today’s date.
For example today’s date is 2021-02-26 which will give the date of the first Monday next month to 2021-03-01. If we step one month ahead today is 2021-03-26 the first Monday of April will be 2021-04-05. Anyone got a clue how to easily get that result?

1 Like
<?xml version="1.0" encoding="UTF-8"?>
	<robot driver="universal" close-on-completion="true"
		<capability name="SEARCH_ALL_WINDOWS" value="true" />
		<capability name="CLOSE_ALL_WINDOWS" value="false" />


			def first_monday = RString.of('')

			def day_name = RString.of('')

			def day_string = RString.of('')

			def firstmondayboolean = RBoolean.fromCanonical('false')

			def today = RDateTime.fromCanonical('2021-03-03T09:34:11-06:00[America/Chicago]')

			def day_num = RNumber.fromCanonical('0')

			com.workfusion.rpa.helpers.RPA.metaClass.static.$ = {
				Closure c ->
			} // Support for Expression action. Should be implemented in RPA class in next release.

			today =

			while ((firstmondayboolean) == (RBoolean.fromCanonical('false'))) {

				input = ['today'],
				output = 'today'
				def customeScript() {
					today =;


				// Do not remove! Custom action customeScript will be invoked here.
				customScripActionCall_customeScript: {}

				day_string = RString.of(today.toRepresentation("dd;en;" + java.time.ZoneId.systemDefault()))

				day_name = RString.of(today.toRepresentation("EEEE;en;" + java.time.ZoneId.systemDefault()))

				day_num =  RNumber.fromRepresentation("${day_string}","0;en")

				if ((day_name) == (RString.of("Monday"))) {

					if ((day_num) <= (RNumber.fromCanonical('7'))) {

						firstmondayboolean = RBoolean.fromCanonical("true")

					} else {

						firstmondayboolean = RBoolean.fromCanonical("false")


				} else {

					firstmondayboolean = RBoolean.fromCanonical("false")



			first_monday = RString.of(today.toRepresentation("yyy-MM-dd;en;" + java.time.ZoneId.systemDefault()))

			putAt("day_num", day_num)
			putAt("firstmondayboolean", firstmondayboolean)
			putAt("first_monday", first_monday)
			putAt("day_string", day_string)
			putAt("today", today)
			putAt("day_name", day_name)
<export include-original-data="true">
	<single-column name="day_num"
		value="${day_num.toCanonicalRepresentation()}" />
	<single-column name="firstmondayboolean"
		value="${firstmondayboolean.toCanonicalRepresentation()}" />
	<single-column name="first_monday"
		value="${first_monday.toCanonicalRepresentation()}" />
	<single-column name="day_string"
		value="${day_string.toCanonicalRepresentation()}" />
	<single-column name="today"
		value="${today.toCanonicalRepresentation()}" />
	<single-column name="day_name"
		value="${day_name.toCanonicalRepresentation()}" />

This is what it looks like in my Recorder. So maybe you can use the bot task code and this picture to see how I did it. Let me know if you have any questions! (1.1 KB)

actually, why don’t I just attach the rpae file


Thanks you @ryule I will test the whole rpae file. I let you know how it goes.

1 Like

Many thanks once again @ryule. The script worked perfectly.

1 Like

Glad I could help @jockej !

1 Like