Total number of the current month
#1
Posted 28 March 2006 - 07:59 AM
May I ask, do anybody know how to calculate the total number of current month? or the last day of current month? For example,
1) MARCH 2006 = 31 days.
2) APRIL 2006 = 30 days
Thank you
Kee
#2
BoBo
Posted 28 March 2006 - 08:44 AM
FormatTime
--------------------------------------------------------------------------------
Transforms a YYYYMMDDHH24MISS timestamp into the specified date/time format.
FormatTime, OutputVar [, YYYYMMDDHH24MISS, Format]
YYYYMMDD... - Leave this parameter blank to use the current local date and time. Otherwise, specify all or the leading part of a timestamp in the YYYYMMDDHH24MISS format. If the date and/or time portion of the timestamp is invalid -- such as February 29th of a non-leap year -- the date and/or time will be omitted from OutputVar. Although only years between 1601 and 9999 are supported, a formatted time can still be produced for earlier years as long as the time portion is valid.
FormatTime, OutPutVar, 20060331, ShortDate ; valid date MsgBox % OutPutVar FormatTime, OutPutVar, 20060332, ShortDate ; invalid date - no output MsgBox % OutPutVar
#3
Posted 28 March 2006 - 09:01 AM
Thanks for your help. I just managed to find a post from PenP. after some amendment on the code, now the coding can be calculate the length of the current month.
Get the solution from following thread.
http://www.autohotke... ... ight=month
yday = %a_mday%
ymonth = %a_mon%
yyear = %a_year%
if ymonth = 01
{
yday = 31
}
else if ymonth = 02
{ yday = 28
leapyear = %a_year%
envdiv, leapyear, 4
envmult, leapyear, 4
envsub, leapyear, %a_year%
ifequal leapyear, 0
{
yday = 29
}
}
else if ymonth = 03
{
yday = 31
}
else if ymonth = 04
{
yday = 30
}
else if ymonth = 05
{
yday = 31
}
else if ymonth = 06
{
yday = 30
}
else if ymonth = 07
{
yday = 31
}
else if ymonth = 08
{
yday = 31
}
else if ymonth = 09
{
yday = 30
}
else if ymonth = 10
{
yday = 31
}
else if ymonth = 11
{
yday = 30
}
else if ymonth = 12
{
yday = 31
}
;}
MsgBox, This month have: `t%yday% days.
#5
BoBo
Posted 28 March 2006 - 10:47 AM
TimeStamp= 20060229
Status := BoBoLDOM(TimeStamp)
MsgBox % TimeStamp "=" Status ; caller section for testing purpose
BoBoLDOM(TimeStamp)
{
FormatTime, DayNum,% TimeStamp,dd
FormatTime, Month,% TimeStamp,MM
If InStr(DayNum,31) OR InStr(DayNum,30) InStr(DayNum,29) OR InStr(DayNum,28)
Return ("VALID") ; MsgBox Day %DayNum% is a valid day in %Month%
Else
Return ("INVALID") ; MsgBox Day %DayNum% isn't a valid day in %Month%
}Tested. 8)
#6
Posted 28 March 2006 - 11:22 AM
TimeStr=20000229
ValidDate := IsDateValid(TimeStr)
If ValidDate
Msgbox % TimeStr " is a Valid Date"
else
Msgbox % TimeStr " is an Invalid Date!"
return
IsDateValid(TimeStr)
{
FormatTime,Dt,%TimeStr%,d
If Dt =
Return 0
else
Return 1
}Regards,
#7
BoBo
Posted 28 March 2006 - 11:36 AM
Thanks. 8)
#8
Posted 29 March 2006 - 12:00 AM
#9
Posted 29 March 2006 - 02:09 AM
IsDateValid(TimeStr) {
FormatTime,Dt,%TimeStr%,d
Return DT > ""
}If you like it more cryptic, useReturn 1-!DT
#10
Posted 29 March 2006 - 06:27 AM
Thanks a lot.
If you like it more cryptic, use
Return 1-!DT
:shock:
Can you please explain/give me one more example on this. I've never used anything like it!
Please...
Regards,
#11
Posted 29 March 2006 - 07:33 AM
If valid, DT is a number between 1 and 31, which is true; !DT transform it to false, ie. 0 when used in a numeric expression.
If invalid, DT is empty, but !DT transforms it from implicit false to true, ie. 1 when used in a numeric expression.
So, 1 - !DT is 0 (false) if DT is invalid, and 1 (true) if valid.
Very smart and tricky... :-)
We can also use Return not !DT (!!DT doesn't work...) or simply Return DT > 0.
#12
Posted 29 March 2006 - 08:15 AM
If valid, DT is a number between 1 and 31, which is true; !DT transform it to false, ie. 0 when used in a numeric expression.
If invalid, DT is empty, but !DT transforms it from implicit false to true, ie. 1 when used in a numeric expression.
So, 1 - !DT is 0 (false) if DT is invalid, and 1 (true) if valid.
Nicely explained.. Thanks a lot PhiLho..
One more thing. I understand Zero is False and any other number is True
But why does this not work? : IfEqual,DT,,Return 0
Regards,
#13
Posted 29 March 2006 - 10:45 AM
Works for me...But why does this not work? : IfEqual,DT,,Return 0
IsDateValid(_timeStr) {
FormatTime DT, %_timeStr%, d
IfEqual DT, , Return 0
Return 1
}
MsgBox % IsDateValid("20060330") IsDateValid("20060230")
#14
Posted 29 March 2006 - 11:05 AM
Thanks PhiLho. Regards,
#15
Posted 29 March 2006 - 04:38 PM
Chris: should not "!!x" work? Or "not not x"?
"not !x", "!(! x)" and "not (not x)" do work, but "! not x" does not.




