how to print previous date
Moderator: DosItHelp
how to print previous date
hi.
help me out...
how to print previous date in a variable
eg:
today is 04/08/2010
output:
030810
help me out...
how to print previous date in a variable
eg:
today is 04/08/2010
output:
030810
Re: how to print previous date
Code: Select all
@echo off
echo WScript.Echo DateAdd("D", WScript.Arguments(0), Now)> "%temp%\dt+.vbs"
call :dayadd -1
echo [today-1] %$d:/=%
call :dayadd +1
echo [today+1] %$d:/=%
del /q "%temp%\dt+.vbs"
pause
goto :eof
:dayadd
for /f "tokens=1*" %%i In ('cscript //Nologo "%temp%\dt+.vbs" %~1') do set "$d=%%i"
goto :eof
Re: how to print previous date
HI thanks man,
but is they anyother way to do it without using wscript
but is they anyother way to do it without using wscript
Re: how to print previous date
This is complicated. Batch can't calculate with DateTime values directly. You could calculate "julian days" from your date, subtract 1 and calculate it back.
http://www.dostips.com/DtTipsDateTime.php#Function.date2jdate
http://www.dostips.com/DtTipsDateTime.php#Function.jdate2date
Regards
aGerman
http://www.dostips.com/DtTipsDateTime.php#Function.date2jdate
http://www.dostips.com/DtTipsDateTime.php#Function.jdate2date
Regards
aGerman
Re: how to print previous date
ohh ok thnks agerman
then only this way is possible i have to store a date in a text file and copy that next day.
then only this way is possible i have to store a date in a text file and copy that next day.
Re: how to print previous date
Didn't you try the functions I linked?
You could calculate %Ytoday%, %Mtoday% and %Dtoday% from %date%. But this depends on the format that echo %date% would return. It's DD.MM.YYYY for my settings, but I don't know which format it is for your settings.
Regards
aGerman
Code: Select all
@echo off &setlocal
set Ytoday=2010
set Mtoday=08
set Dtoday=08
:: calculate the julian days
call :date2jdate jd %Ytoday% %Mtoday% %Dtoday%
:: subtract 1
set /a jd-=1
:: calculate the new values
call :jdate2date %jd% Yyesterday Myesterday Dyesterday
:: combine the returned values
echo %Dyesterday%%Myesterday%%Yyesterday:~-2%
pause
goto :eof
:date2jdate JD YYYY MM DD -- converts a gregorian calender date to julian day format
:: -- JD [out] - julian days
:: -- YYYY [in] - gregorian year, i.e. 2006
:: -- MM [in] - gregorian month, i.e. 12 for december
:: -- DD [in] - gregorian day, i.e. 31
:$reference http://aa.usno.navy.mil/faq/docs/JD_Formula.html
:$created 20060101 :$changed 20080219 :$categories DateAndTime
:$source http://www.dostips.com
SETLOCAL
set "yy=%~2"&set "mm=%~3"&set "dd=%~4"
set /a "yy=10000%yy% %%10000,mm=100%mm% %% 100,dd=100%dd% %% 100"
if %yy% LSS 100 set /a yy+=2000 &rem Adds 2000 to two digit years
set /a JD=dd-32075+1461*(yy+4800+(mm-14)/12)/4+367*(mm-2-(mm-14)/12*12)/12-3*((yy+4900+(mm-14)/12)/100)/4
ENDLOCAL & IF "%~1" NEQ "" (SET %~1=%JD%) ELSE (echo.%JD%)
EXIT /b
:jdate2date JD YYYY MM DD -- converts julian days to gregorian date format
:: -- JD [in] - julian days
:: -- YYYY [out] - gregorian year, i.e. 2006
:: -- MM [out] - gregorian month, i.e. 12 for december
:: -- DD [out] - gregorian day, i.e. 31
:$reference http://aa.usno.navy.mil/faq/docs/JD_Formula.html
:$created 20060101 :$changed 20080219 :$categories DateAndTime
:$source http://www.dostips.com
SETLOCAL ENABLEDELAYEDEXPANSION
set /a L= %~1+68569, N= 4*L/146097, L= L-(146097*N+3)/4, I= 4000*(L+1)/1461001
set /a L= L-1461*I/4+31, J= 80*L/2447, K= L-2447*J/80, L= J/11
set /a J= J+2-12*L, I= 100*(N-49)+I+L
set /a YYYY= I, MM=100+J, DD=100+K
set MM=%MM:~-2%
set DD=%DD:~-2%
( ENDLOCAL & REM RETURN VALUES
IF "%~2" NEQ "" (SET %~2=%YYYY%) ELSE echo.%YYYY%
IF "%~3" NEQ "" (SET %~3=%MM%) ELSE echo.%MM%
IF "%~4" NEQ "" (SET %~4=%DD%) ELSE echo.%DD%
)
EXIT /b
You could calculate %Ytoday%, %Mtoday% and %Dtoday% from %date%. But this depends on the format that echo %date% would return. It's DD.MM.YYYY for my settings, but I don't know which format it is for your settings.
Regards
aGerman
Re: how to print previous date
thanks agerman,
i seen that link .......i wrote most of my scripts in shell. but this is first time in dos .......just to print previous date i have to write that much big script. so i didnt gone through that julian matter.
i seen that link .......i wrote most of my scripts in shell. but this is first time in dos .......just to print previous date i have to write that much big script. so i didnt gone through that julian matter.
Re: how to print previous date
hi agerman,
when i ran this script yesterday it displayed previous date(070810) ..ok its fine.........
but when i ran today it dispalyed same date(070810)
when i ran this script yesterday it displayed previous date(070810) ..ok its fine.........
but when i ran today it dispalyed same date(070810)
Re: how to print previous date
Of course. The date is "hard coded":
Please give me the date format of your settings.
Open a command prompt as follows:
press [Windows]+[R]
write cmd
click OK
Now write echo %date%
and hit [Enter]
Post me the output, then I can make it working dynamic.
Regards
aGerman
set Ytoday=2010
set Mtoday=08
set Dtoday=08
Please give me the date format of your settings.
Open a command prompt as follows:
press [Windows]+[R]
write cmd
click OK
Now write echo %date%
and hit [Enter]
Post me the output, then I can make it working dynamic.
Regards
aGerman
Re: how to print previous date
This might help.
This tip is here (newdate.bat):
http://www.fpschultze.de/modules/PDdown ... d=1&lid=35
The original part is this:
As yo can see this part of the batch script is capable of handling all types of date format.
Question remains (should be checked with localized version of Windows) if it can handle non-English versions ("(mm" should then be replaced).
Saso
This tip is here (newdate.bat):
http://www.fpschultze.de/modules/PDdown ... d=1&lid=35
The original part is this:
Code: Select all
REM echo MM-DD-YYYY DD-MM-YYYY DD.MM.YYYY DD/MM/YYYY
:Begin --------------------------------------------------------------
echo. | date | FIND "(mm" > NUL
if NOT errorlevel 1 %0 : %OS%Parse MM DD
%0 : %OS%Parse DD MM
:Windows_NTParse ----------------------------------------------------
for /F "tokens=1-4 delims=/.- " %%A in ('date /T') do if %%D!==! (
set %3=%%A&set %4=%%B&set YYYY=%%C
) else (
set DOW=%%A&set %3=%%B&set %4=%%C&set YYYY=%%D)
goto End
As yo can see this part of the batch script is capable of handling all types of date format.
Question remains (should be checked with localized version of Windows) if it can handle non-English versions ("(mm" should then be replaced).
Saso
Re: how to print previous date
hi agerman,
its below one
Tue 08/10/2010
its below one
Tue 08/10/2010
Re: how to print previous date
Try
Regards
aGerman
Code: Select all
@echo off &setlocal
:: calculate the julian days
for /f "tokens=2-4 delims=/ " %%a in ("%date%") do call :date2jdate jd %%c %%a %%b
:: subtract 1
set /a jd-=1
:: calculate the new values
call :jdate2date %jd% Yyesterday Myesterday Dyesterday
:: combine the returned values
echo %Dyesterday%%Myesterday%%Yyesterday:~-2%
pause
goto :eof
:date2jdate JD YYYY MM DD -- converts a gregorian calender date to julian day format
:: -- JD [out] - julian days
:: -- YYYY [in] - gregorian year, i.e. 2006
:: -- MM [in] - gregorian month, i.e. 12 for december
:: -- DD [in] - gregorian day, i.e. 31
:$reference http://aa.usno.navy.mil/faq/docs/JD_Formula.html
:$created 20060101 :$changed 20080219 :$categories DateAndTime
:$source http://www.dostips.com
SETLOCAL
set "yy=%~2"&set "mm=%~3"&set "dd=%~4"
set /a "yy=10000%yy% %%10000,mm=100%mm% %% 100,dd=100%dd% %% 100"
if %yy% LSS 100 set /a yy+=2000 &rem Adds 2000 to two digit years
set /a JD=dd-32075+1461*(yy+4800+(mm-14)/12)/4+367*(mm-2-(mm-14)/12*12)/12-3*((yy+4900+(mm-14)/12)/100)/4
ENDLOCAL & IF "%~1" NEQ "" (SET %~1=%JD%) ELSE (echo.%JD%)
EXIT /b
:jdate2date JD YYYY MM DD -- converts julian days to gregorian date format
:: -- JD [in] - julian days
:: -- YYYY [out] - gregorian year, i.e. 2006
:: -- MM [out] - gregorian month, i.e. 12 for december
:: -- DD [out] - gregorian day, i.e. 31
:$reference http://aa.usno.navy.mil/faq/docs/JD_Formula.html
:$created 20060101 :$changed 20080219 :$categories DateAndTime
:$source http://www.dostips.com
SETLOCAL ENABLEDELAYEDEXPANSION
set /a L= %~1+68569, N= 4*L/146097, L= L-(146097*N+3)/4, I= 4000*(L+1)/1461001
set /a L= L-1461*I/4+31, J= 80*L/2447, K= L-2447*J/80, L= J/11
set /a J= J+2-12*L, I= 100*(N-49)+I+L
set /a YYYY= I, MM=100+J, DD=100+K
set MM=%MM:~-2%
set DD=%DD:~-2%
( ENDLOCAL & REM RETURN VALUES
IF "%~2" NEQ "" (SET %~2=%YYYY%) ELSE echo.%YYYY%
IF "%~3" NEQ "" (SET %~3=%MM%) ELSE echo.%MM%
IF "%~4" NEQ "" (SET %~4=%DD%) ELSE echo.%DD%
)
EXIT /b
Regards
aGerman
Re: how to print previous date
yes thanks agerman
its working
kindly solve that problem which i posted in delete column forum.......its very urgent.
its working
kindly solve that problem which i posted in delete column forum.......its very urgent.
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Re: how to print previous date
aGerman --
not sure about languages nor OS versions, but here's a trick for (XP English)regional settings:
From there you can calculate the julian dates using yy mm dd
not sure about languages nor OS versions, but here's a trick for (XP English)regional settings:
Code: Select all
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('"echo.|date"') do (
for /f "tokens=1-3 delims=/.- " %%A in ("%Date:* =%") do (
set %%a=%%A&set %%b=%%B&set %%c=%%C)
)
)
set /a "yy=10000%yy% %% 10000 %% 2000 + 2000,mm=100%mm% %% 100,dd=100%dd% %% 100"
Re: how to print previous date
It only works on an english version, because you get something like
"current date is 10/08/2010"
"Enter new date: (DD-MM-YY)"
or it also works with
"Enter new date: (YY-DD-MM)"
but in german you got
"Geben Sie das neue Datum ein: (TT-MM-JJ)"
So the script can't find %yy% nor %dd%, and I can't see a way how to decide which chars are for the year or day,
perhaps in some countries you get
"?#+#++ : (RR-ZZ-XX)"
@!k what is the response in your version?
"current date is 10/08/2010"
"Enter new date: (DD-MM-YY)"
or it also works with
"Enter new date: (YY-DD-MM)"
but in german you got
"Geben Sie das neue Datum ein: (TT-MM-JJ)"
So the script can't find %yy% nor %dd%, and I can't see a way how to decide which chars are for the year or day,
perhaps in some countries you get
"?#+#++ : (RR-ZZ-XX)"
@!k what is the response in your version?