My Blog List

Monday, 22 October 2012

How to create an awesome calender of all years in your PC

Today I will teach you to make a calender for you computer.....

This trick is very easy and can be done in minutes........

All you have to do is to open notepad and copy+paste this code and in save as "All files"
and rename it as "calender.BAT"

@ECHO OFF

:: batch for generating calendars

IF "%~1"=="/?" (
ECHO START "%~NX0" WITHOUT ARGUMENTS AND THEN ENTER THE YEAR.
ECHO "%~NX0" WILL OPEN IN IT'S OWN WINDOW TO AVOID RESIZING
ECHO AN EXISTING WINDOW.
ECHO.
ECHO A SCREEN RESOLUTION AND/OR FONT SIZE THAT CAN DISPLAY
ECHO CMD WINDOWS OF 96 COLUMNS AND 39 LINES IS REQUIRED.
ECHO SOME CONFIGURATIONS MAY USE SCROLL BARS TO ACHIEVE
ECHO THIS.
EXIT /B
)

:: The current codepage is stored in variable %CodePage%,
:: then changed to 850 to facilitate box drawing characters.....

FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%~A) DO SET CodePage=%%B
CHCP 850 >NUL 2>&1

:: The title can be used to falicitate custom window
:: positioning via the properties menu of "calendars..."
:: /max is used so as much content as possible is visable
:: without moving the window. /max must be removed for
:: custom window positing.....

IF NOT "%~1 %~2"=="WINDOW SIZE" (
START "CALENDARS..." /MAX CMD /C "%~F0" WINDOW SIZE

REM Restore the original codepage before exiting.....

CHCP %CodePage% >NUL 2>&1
EXIT /B
)
MODE CON:COLS=96 LINES=39
SETLOCAL ENABLEDELAYEDEXPANSION

:loop
FOR %%Z IN (jan feb mar apr may jun jul aug sep oct nov dec year day leap noleap length test) DO SET %%Z=
SET /P year=Enter a year to see it's calendar, or nothing to exit, then press enter:
IF NOT DEFINED year (

REM Restore the original codepage before exiting.....

CHCP %CodePage% >NUL 2>&1
EXIT /B
)

::Test that the input is only numbers...

SET test=!year!
FOR /l %%Z IN (0 1 9) DO IF DEFINED test SET "test=!test:%%Z=!"
IF DEFINED test CLS&GOTO loop
:zero
IF NOT DEFINED year (
:error
cls
echo The year entered can not be accepted.
echo.
pause
CLS
GOTO loop
)

:: remove leading zeros, if any...

IF "%year:~0,1%"=="0" SET year=%year:~1%&&GOTO zero

:: The %processor_architecture% test is used to test
:: limits of caculations, if the variable is undefined
:: or unrecognised the test will fall through and complete
:: anyway, if the limit is surpassed this way the results may
:: not be valid. The tested number is ~80% of the limit of the
:: os so that year + year / 4 yields a valid result.

IF /I "!processor_architecture!"=="x86" (
IF !year! gtr 1717986917 GOTO :error
) else (
IF NOT "!processor_architecture:64=!"=="!processor_architecture!" (
IF !year! gtr 7378697629483820645 GOTO :error
)
)

:: Generate the first day of the year, 0=sun, 1=mon,...,6=sat
:: A 365 day year ofsets by one day, so the next year will start
:: the next day (i.e. 2009 starts on thr and 2010 starts on fri)
:: an extra day must be added for every leapyear. Using modulo
:: 7 on the total of offset days reviels the starting day of the
:: year. one day must also be removed if the year is a leap year
:: because the below will add one for it, the remainder for non
:: leap years is not an issue because set /a only returns whole
:: numbers.

SET /A day=(year + year / 4) - (year / 100 - year / 400)
SET /A leap=year %% 400
SET /A noleap=year %% 100
IF !leap! GTR 0 (
IF !noleap! NEQ 0 SET /A leap=year %% 4
)
IF %leap%==0 SET /A day-=1
SET /A day%%=7

:: For each year every month is padded to is starting offset
:: with spaces, january has the original offset generated above.
:: each additional offset is generated by adding the total days of
:: the previous month then processing it by modulo 7.
:: The days are stored in a varianle to display later, these variables
:: are padded to 111 characters using spaces for display purposes.

FOR %%U IN (jan feb mar apr may jun jul aug sep oct nov dec) DO (
FOR %%V IN (jan mar may jul aug oct dec) DO IF /I %%U==%%V SET length=31
FOR %%W IN (apr jun sep nov) DO IF /I %%U==%%W SET length=30
IF /I %%U==feb (
IF !leap!==0 (
SET length=29
) else (
SET length=28
)
)
FOR /l %%X IN (1 1 !day!) DO SET "%%U=!%%U! "
FOR /l %%Y IN (1 1 !length!) DO (
IF %%Y lss 10 (
SET "%%U=!%%U!%%Y "
) else (
SET "%%U=!%%U!%%Y "
)
)
FOR /l %%Z IN (!length! 1 54) DO IF "!%%U:~110!"=="" SET "%%U=!%%U! "
SET /A day=^(day + length^) %% 7
)
:test

:: The results are displayed below using substrings of each month's
variable.

cls
TITLE THE CALENDAR FOR THE YEAR OF %YEAR%
echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo. º JANUARY º º FEBUARY º º MARCH º º APRIL º
echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo. ºS M T W T F S º ºS M T W T F S º ºS M T W T F S º ºS M T W T F S º
echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo. º%JAN:~0,20%º º%FEB:~0,20%º º%MAR:~0,20%º º%APR:~0,20%º
echo. º%JAN:~21,20%º º%FEB:~21,20%º º%MAR:~21,20%º º%APR:~21,20%º
echo. º%JAN:~42,20%º º%FEB:~42,20%º º%MAR:~42,20%º º%APR:~42,20%º
echo. º%JAN:~63,20%º º%FEB:~63,20%º º%MAR:~63,20%º º%APR:~63,20%º
echo. º%JAN:~84,20%º º%FEB:~84,20%º º%MAR:~84,20%º º%APR:~84,20%º
echo. º%JAN:~105% º º%FEB:~105% º º%MAR:~105% º º%APR:~105% º
echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo. º MAY º º JUNE º º JULY º º AUGUST º
echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo. ºS M T W T F S º ºS M T W T F S º ºS M T W T F S º ºS M T W T F S º
echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo. º%MAY:~0,20%º º%JUN:~0,20%º º%JUL:~0,20%º º%AUG:~0,20%º
echo. º%MAY:~21,20%º º%JUN:~21,20%º º%JUL:~21,20%º º%AUG:~21,20%º
echo. º%MAY:~42,20%º º%JUN:~42,20%º º%JUL:~42,20%º º%AUG:~42,20%º
echo. º%MAY:~63,20%º º%JUN:~63,20%º º%JUL:~63,20%º º%AUG:~63,20%º
echo. º%MAY:~84,20%º º%JUN:~84,20%º º%JUL:~84,20%º º%AUG:~84,20%º
echo. º%MAY:~105% º º%JUN:~105% º º%JUL:~105% º º%AUG:~105% º
echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo. º SEPTEMBER º º OCTOBER º º NOVEMBER º º DECEMBER º
echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo. ºS M T W T F S º ºS M T W T F S º ºS M T W T F S º ºS M T W T F S º
echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo. º%SEP:~0,20%º º%OCT:~0,20%º º%NOV:~0,20%º º%DEC:~0,20%º
echo. º%SEP:~21,20%º º%OCT:~21,20%º º%NOV:~21,20%º º%DEC:~21,20%º
echo. º%SEP:~42,20%º º%OCT:~42,20%º º%NOV:~42,20%º º%DEC:~42,20%º
echo. º%SEP:~63,20%º º%OCT:~63,20%º º%NOV:~63,20%º º%DEC:~63,20%º
echo. º%SEP:~84,20%º º%OCT:~84,20%º º%NOV:~84,20%º º%DEC:~84,20%º
echo. º%SEP:~105% º º%OCT:~105% º º%NOV:~105% º º%DEC:~105% º
echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
GOTO loop
 Enjoy...!!
 
My Great Web page