![]() ![]() IF %v_mm% GTR 9 (SET v_mm_str=%v_mm%) ELSE (SET v_mm_str=0%v_mm%)ĮCHO DATEMATH - add or subtract days from a date = new date If %v_dd% LEQ 31 goto s_add_subtract_days_DONE If %v_dd% LEQ 30 goto s_add_subtract_days_DONE If %v_dd% LEQ 29 goto s_add_subtract_days_DONE If %v_dd% LEQ 28 goto s_add_subtract_days_DONE If %v_leapyear% EQU %v_yy% goto s_subtract_leapyear If %v_mm% LEQ 12 goto s_subtract_days_%v_mm% If %v_leapyear% NEQ %v_yy% goto s_adjust_month_year ![]() If %v_dd% GEQ 1 goto s_add_subtract_days_DONE SET /a v_dd_int=%v_sumdays1% - %v_sumdays2%ĮCHO DATEMATH - Subtracting one date from another = days difference If %v_yy2% GTR 99 goto s_validate2nd_month :: Subtracting one date from another :::::: IF %v_mm% LEQ 9 (SET v_mm_str=0%v_mm%) ELSE (SET v_mm_str=%v_mm%)ĮCHO DATEMATH - Convert date only (no maths) :: Determine which function to perform - ADD, SUBTRACT or CONVERT :: at this point v_yy contains a 4 digit year "1"Įcho CALL DateMath YYYY MM DD - YYYY2 MM2 DD2Įcho Will set variable _dd_int to the signed differenceĮcho between the 2 dates (measured in days)Įcho Will set the following variables to the result ofĮcho adding or substracting days from the initial date:Įcho _yy_int is in YYYY format, even if YY format was originally supplied. "01"Įcho 'int' variables leading zeros are stripped e.g. :: If DateMath detects an error, variable _dd_int is set to 999999.Įcho DateMath will set the variables as listed belowĮcho 'str' variables include leading zeros e.g. :: DateMath, a general purpose date math routine Let's implement the above logic in a Java program.How-to: Add or subtract days from any date - DateMath.cmdĬopy the script below or download here and save as DateMath.cmd off Note that the number of days must be positive. In the same way, we can also add days to the current date. In this method, we have passed a negative value because we are subtracting days from the current date. ![]() Now let's subtract the days by calling the add() method and Calendar.DATE constant. In order to get the current date first, we have created an instance of the Calendar class, after that called the getTime() method that prints the current date and time on the console. In the following Java program, we have used the Java Calendar class. In this section, we will discuss how to subtract number of days from current date and any particular day. In Java, dealing with date and time is not much difficult task because Java provides API for date and time that makes tasks easier for the developers. Next → ← prev Java Subtract Days from Current Date ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |