WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Time - Timer and Date Functions
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How Many Days in a Month?

Keywords:    days in a month

Question:

Is there an easy way to figure out how many days there are in a month? Let's say I need to know February 2052?

Answer:

Find the first day of next month and use dayDiff()
   month=2
   year=2052

   ;make ymd string

   mymonth=strcat(year,":",month,":01:00:00:00")
   nextmonth=TimeAdd(mymonth,"00:01:00:00:00:00")
   daze=TimeDiffDays(nextmonth,mymonth)
   message("",daze)

Determine Whether or Not Today is the Last Day of Month

Question:

I have a program I want to run only on the last day of the month (I have a Winbatch written as a scheduler that runs constantly). As I am a beginner w/ Winbatch and also not a programmer I am having trouble coming up w/ an easy way to do this. My only thought so far has been to figure out what month and day it is and then use a series of "if" statements to test if today is 1/31 or 2/28(29) or 3/31 or 4/30 etc. then run the program. There must be a simpler way. Any ideas would be appreciated.

Answer:

today=TimeYmdHms()
;today="1998:12:31:00:00:00" ; for testing
thismonth=ItemExtract(2,today,":")
tomorrow=TimeAdd(today,"0000:00:01:00:00:00")
nextmonth=ItemExtract(2,tomorrow,":")

if thismonth!=nextmonth
Message(today,"Is the last day of this month")
else
Message(today,"NOT last day of month")
endif
exit

Article ID:   W13871
Filename:   How Many Days in a Month.txt
File Created: 1999:04:15:16:56:56
Last Updated: 1999:04:15:16:56:56