_Maze

date counter

Apr 23rd, 2017
127
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. ::-------------------------------------
  3. :: Simple script that pulls the current date and adds specified amount of days to it
  4. :: Known flaws:
  5. :: Displays incorrect date if day count is greather than 45, everything below 45 should work fine.
  6. :: Date format used is DD-MM-YYYY
  7. ::-------------------------------------
  8. :: days to add to current date
  9. set days=7
  10. :: gets current date
  11. for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
  12.      set dow=%%h
  13.      set month=%%j
  14.      set day=%%i
  15.      set year=%%k
  16. )
  17. :: sets current date for variable "CurrentDate"
  18. set CurrentDate=%day%-%month%-%year%
  19. :: adds day count to current date
  20. set /a "date2=%day%+%days%"
  21. :: Checks if the day count is greather than 31
  22. if %date2% gtr 31 GOTO next
  23. GOTO skip
  24. :next
  25. set /a "dateE=%date2%-31
  26.  
  27. :: checks if day count is less than 10 and if it is adds "0" before it
  28. if %dateE% LSS 10 set date2=0%dateE%
  29. :: Changes to next month
  30. set /a "month2=%month%+1"
  31. :: checks if month isn't October, November or December and adds "0" before it
  32. if %month2% LSS 10 set month=0%month2%
  33.  
  34. :: Changes variable "NewDate" new date
  35. :skip
  36. set NewDate=%date2%-%month%-%year%
  37. if %date2% gtr 31 set NewDate=%dateE%-%month%-%year%
  38. :: Example
  39. ECHO ----------------------------
  40. ECHO current date is %CurrentDate%
  41. ECHO We're adding %days% days
  42. ECHO And now the date is %NewDate%
  43. ECHO - - - - - - - - - - - - - -
  44.  
  45. :: The variable for added days is "%days%"
  46. :: The variable for current date is "%CurrentDate%"
  47. :: The variable for new date is %NewDate%
  48.  
  49.  
  50. pause
RAW Paste Data