Created
April 26, 2012 15:37
-
-
Save FlorianWolters/2500429 to your computer and use it in GitHub Desktop.
Prints out the last day of the current month.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
REM Prints out the last day of the current month. | |
REM | |
REM Author: Florian Wolters <[email protected]> | |
REM Link..: http://github.com/FlorianWolters | |
REM | |
REM Copyright (C) 2012 by Florian Wolters. All rights reserved. | |
REM | |
REM This program is free software: you can redistribute it and/or modify it | |
REM under the terms of the GNU Lesser General Public License as published by the | |
REM Free Software Foundation, either version 3 of the License, or (at your | |
REM option) any later version. | |
REM | |
REM This program is distributed in the hope that it will be useful, but WITHOUT | |
REM ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
REM FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | |
REM for more details. | |
REM | |
REM You should have received a copy of the GNU Lesser General Public License | |
REM along with this program. If not, see http://gnu.org/licenses/lgpl.txt. | |
SETLOCAL | |
REM Uncomment and set for tests. | |
REM SET DATE=01.02.2012 | |
SET CURRENT_MONTH=%DATE:~3,2% | |
SET CURRENT_YEAR=%DATE:~6,4% | |
SET RESULT_DAY=31 | |
FOR %%? IN (04 06 09 11) DO IF %CURRENT_MONTH%==%%? SET RESULT_DAY=30 | |
IF NOT %CURRENT_MONTH% == 02 GOTO EOF | |
REM Check whether the year is a leap year. | |
:CHECK_LEAP_YEAR | |
SET /A ISLEAP=%CURRENT_YEAR% %% 4 | |
IF NOT %ISLEAP% == 0 GOTO NOT_LEAP_YEAR | |
SET /A ISLEAP=%CURRENT_YEAR% %% 100 | |
IF NOT %ISLEAP% == 0 GOTO IS_LEAP_YEAR | |
SET /A ISLEAP=%CURRENT_YEAR% %% 400 | |
IF NOT %ISLEAP% == 0 GOTO NOT_LEAP_YEAR | |
:IS_LEAP_YEAR | |
SET RESULT_DAY=29 | |
GOTO EOF | |
:NOT_LEAP_YEAR | |
SET RESULT_DAY=28 | |
:EOF | |
SET RESULT=%RESULT_DAY% | |
ECHO %RESULT% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requirements
NOTICE: May also work with older versions.
Usage
lastDayOfCurrentMonth.cmd > debug.log
License
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://gnu.org/licenses/lgpl.txt.