Topic Options
#1360 - 11/24/03 12:28 PM Last Day of each month
Herrick Offline
Junior Member

Registered: 11/24/03
Posts: 1
Hi,

I downloaded the eval copy of wincron because I need to run a task on the last day of a month... I read lots of exemple with patern matching and exclusion, but is there a way to do it easyly without making a patern on all these ? What about febuary... Is there a way without entering all the years with 28th and those with 29th of febuary ? I wish there would be a simple way to use "last day of everymonth"

31/01
28/02 29/02
31/03
30/04
31/05
30/06
31/07
31/08
30/09
31/10
30/11
31/12

Top
#1361 - 11/24/03 02:40 PM Re: Last Day of each month
Luke Tomasello Administrator Online   content
Member

Registered: 09/17/00
Posts: 739
Loc: San Jose, CA., USA
Sure, we can set a trigger on the last day of the month.
You'll need the latest version (4.0) of WinCron to run this script.

As you've found, CRON syntax doesn't support a notion of the "last day of the month". But, if we're clever, we can simply look ahead to see if we are about to fall over into the next month!


Code:
  
## Last Day of the Month script
# This script checks each night at 11:59 to see if the next minute
#  will usher in a new month. If so, (put your code in here)
{
	# At 11:59 PM each night... 
	-start -cron 59  23 *   *   *
	
	# Every night at 11:59, check to see of this is the "Last Day Of the Month"
	If LastDayOfMonth() = False Then WCCtrl.Return("break")
		
	# Okay, it's the last day of the month; do stuff...
	Print("It's the last day of the month!")
}
	
Function LastDayOfMonth()
	
	LastDayOfMonth = False
	
	' get the current date/time
	initial_date = now
	
	' this_month contains the number corresponding to the current month.
	this_month = Month(initial_date) 
	
	' check_month contains the number corresponding to the current month + 1 minute.
	check_month = Month(DateAdd("n", 1, initial_date)) 
	
	' are we about to change months?
	If this_month <> check_month Then LastDayOfMonth = True
		
End Function
_________________________
Regards,
Luke Tomasello

Top


Moderator:  Luke Tomasello