InterviewSolution
| 1. |
Solve : Is this batch code correct?? |
|
Answer» Code: [Select]SET dd=%date% %Time% SET /A ex1=%today%-1 minuses the current day by 1, making it yesterday. This is not possible when using dates. If the current day is 01 the outcome will be 0 and if the current day is 08 or 09 Set /A will fail because it will 'see' the date as Octal (base eight), in Octal 8 and 9 are invalid. Also, if today is the first day of the month and you want to get yesterday's date, the month and possibly the year must be decremented as well as the day. e.g. (Based on a date format of dd/mm/yyyy) Current date = 01/01/2010 Current date -1 = 31/12/2009 and Current date = 01/03/2010 Current date -1 = 28/02/2010 To manipulate dates and times I suggest you consider VB scripting. Below is a small script combining batch scripting and VB scripting which will reduce the date by one day. Code: [Select]@echo off setlocal cls set vbs=%temp%\vbs.vbs > %vbs% echo WScript.Echo DateAdd("d",-1,Date) for /f "tokens=* delims=" %%a in ('cscript //nologo %vbs%') do ( set newdate=%%a ) del %vbs% echo Newdate=%newdate% exit /b Hope this helps.Ah, wow. I wasn't even thinking I guess. Well, this definitely helps, I don't know a single thing about VB or VBS, but I'll see what I can do. Thanks Dusty. |
|