| 1. |
Solve : edit to yesterday's date? |
|
Answer» Hi there, You may have to alter the script to suit your date format. New! Improved! You won't have to alter this, it is independent of date format settings. You can fool around with the variables to make different strings as you can see in the 3 examples at the bottom. Code: [Select]@echo off echo Yesterdate = (Date^(^)- 1^)>yesterday.vbs echo Yyyy = DatePart^("YYYY", Yesterdate^)>>yesterday.vbs echo Mm = DatePart^("M" , Yesterdate^)>>yesterday.vbs echo Dd = DatePart^("D" , Yesterdate^)>>yesterday.vbs echo Wscript.Echo Yyyy^&" "^&Mm^&" "^&Dd>>yesterday.vbs FOR /F "tokens=1,2,3 delims= " %%A in ('cscript //nologo yesterday.vbs') do ( set /a Year=%%A set /a Month=%%B set /a Day=%%C ) if %Month% LSS 10 set Month=0%Month% if %Day% LSS 10 set Day=0%Day% REM Examples echo (1) echo. echo Yesterday was: echo. echo Year : %Year% echo Month : %Month% echo Day : %Day% echo. echo (2) echo. echo %Day%/%Month%/%Year% echo. echo (3) echo. echo %Year%%Month%%Day% echo. Output today Friday 10/10/2008: Code: [Select](1) Yesterday was: Year : 2008 Month : 10 Day : 09 (2) 09/10/2008 (3) 20081009Ahhh Dias... Quote O Lord my God, When I in awesome wonder, Although it is -- of course -- immensely flattering to be likened to God, modesty insists that I must decline such a comparison. By the way, if you want to just keep Yesterday.vbs somewhere and call it when you need it, rather than create it from a batch script, it looks like this Code: [Select]Yesterdate = (Date()- 1) Yyyy = DatePart("YYYY", Yesterdate) Mm = DatePart("M" , Yesterdate) Dd = DatePart("D" , Yesterdate) Wd = DatePart("W" , Yesterdate) Wscript.Echo Yyyy&" "&Mm&" "&DdThank you for that but your elevated status is hereby revoked 'cos I couldn't get your New! Improved! version to perform. I think this line:Quote FOR /F "tokens=1,2,3 delims= " %%A in ('yesterday.vbs //nologo') do ( should be: Quote FOR /F "tokens=1,2,3 delims= " %%A in ('cscript //nologo yesterday.vbs') do ( You are right - It depends on which of the two scripting hosts is the default on your system, cscript or wscript. On mine it is cscript, so I can just do... Code: [Select]scriptname.vbs //nologo ...or even (assuming the script file has the .vbs extension)... Code: [Select]scriptname //nologo ...from a batch WITHOUT having to specifically mention cscript.exe, but I forgot that on systems where the other host is the default it would have to use your line, so it is better (more UNIVERSAL) to do it that way, so I have edited the script above. Incidentally, if you get bored with adding //nologo every time, you can make cscript save it as a per-user preference by using it just once with the //S switch when you run a script (any script, it applies to all scripts run with cscript by that user after that, until you change it back again by using //S with //logo) Before (Windows default): Code: [Select]S:\Test\Batch\Yesterday>yesterday Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation. All rights reserved. 2008 10 10 6 Set //nologo as user's cscript default: Code: [Select]S:\Test\Batch\Yesterday>cscript //nologo //s yesterday.vbs Command line options are saved. 2008 10 10 6 After: Code: [Select]S:\Test\Batch\Yesterday>yesterday 2008 10 10 6 To change it back again: Code: [Select]S:\Test\Batch\Yesterday>cscript //logo //s yesterday.vbs Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation. All rights reserved. Command line options are saved. 2008 10 10 6 Back the way we were... Code: [Select]S:\Test\Batch\Yesterday>yesterday Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation. All rights reserved. 2008 10 10 6 |
|