I can determine whether it is leap year in couple of lines of batch script(witout using &) and most other scripting language support one-liner equation to determine whether it is leap year. But I cannot figure out how to do this in dos batch script since DOS does not support operator like (a == 1) to be true or false.
However, I still think it is doable with set /a leapyear=" ... " type of equation with operator like ^ & |. but my head is not clear enough to figure that out.
-Frank
Any one-liner script to determine leap year?
Moderator: DosItHelp
Hi Frank,
in a batchfile this is a solution for the years from 1901-2099
obviously this is the full solution
jeb
in a batchfile this is a solution for the years from 1901-2099
Code: Select all
set /a leapyear=! (%year% %% 4 )
obviously this is the full solution
Code: Select all
set /a leapyear=((!(%year%%%400))^|!(!(%year%%%100)))^&!(%year%%%4)
jeb
jeb,
Thanks! I know it is doable! Again, how do I interpret '^|' and '^&'. I do not seem to find anything reference about these operator(most stuff about DOS scripts I can find by 'set /?', 'for /?', 'if /?', 'call /?', ...)
And this equation will fail if I put <space> between ^ and | or ^ and &.
-Frank
Thanks! I know it is doable! Again, how do I interpret '^|' and '^&'. I do not seem to find anything reference about these operator(most stuff about DOS scripts I can find by 'set /?', 'for /?', 'if /?', 'call /?', ...)
And this equation will fail if I put <space> between ^ and | or ^ and &.
-Frank
jeb wrote:Hi Frank,
in a batchfile this is a solution for the years from 1901-2099Code: Select all
set /a leapyear=! (%year% %% 4 )
obviously this is the full solutionCode: Select all
set /a leapyear=((!(%year%%%400))^|!(!(%year%%%100)))^&!(%year%%%4)
jeb
Hi Frank,
the 'set' command supports '&' "bitwise and", "| bitwise or"
but the & is also the delimeter for the next command on one line.
like
same for the pipe '|'
therefore you need to escape them with '^'
jeb
the 'set' command supports '&' "bitwise and", "| bitwise or"
but the & is also the delimeter for the next command on one line.
like
Code: Select all
set /a var=1 & echo hello
same for the pipe '|'
therefore you need to escape them with '^'
jeb
Hi, Jeb,
Thanks, I thought ^ is 'bitwise exclusive or'. Never thought about it is escape char.
-Frank
Thanks, I thought ^ is 'bitwise exclusive or'. Never thought about it is escape char.
-Frank
jeb wrote:Hi Frank,
the 'set' command supports '&' "bitwise and", "| bitwise or"
but the & is also the delimeter for the next command on one line.
likeCode: Select all
set /a var=1 & echo hello
same for the pipe '|'
therefore you need to escape them with '^'
jeb