Community Page
- www.tech-recipes.com/ Jump to website »
-
Subscribe -
Community
-
Top Commenters
-
Popular Threads
-
Recent Comments
- Go to internet options - general tab. Go to Tabs. Tabs settings. Select "when a new tab is opened, open", and select a blank page. TADA
- Please completely delte my MySpace Profile with all information. I do understand that this will be permanent...
- Thank you! This was very helpful.
- Opps I didn't see lift chair... "The 'gcc compiler' is installed when one installs 'XcodeTools' (via the 'XcodeTools.mpkg' file) from the installation CD (if...
- Sorry if i am repeating anyone but I know if you have mac 10.4.X then on the install disk you can find a copy of xcode...
Tech-Recipes
Cookbook of Tech TutorialsWindows Batch File (.bat) to get current date in MMDDYYYY format. | Computer programming | Tech-Recipes
Started by qdideas · 9 months ago
3 years ago
<ul id="quote">For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a-%%b-%%c)</ul>
There may still be value in the first example it you need to access the seperate mm,dd,yyyy values but this works great for me.
3 years ago
</ul><ul id="quote">For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a-%%b-%%c)</ul>
There may still be value in the first example it you need to access the seperate mm,dd,yyyy values but this works great for me.
hmm.. I tried your oneliner and only could get the day and the year.. I was missing the month.. I tried playing with the tokens and changing it to 1-4, but then I got Tue 08-16-2004 ..
the first iteration on the initial page added an extra space which I didn't like.. thanks for the help!
3 years ago
here it is..
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a%%b%%c)
3 years ago
3 years ago
3 years ago
Idea about getting the current date time in required format is good. I wanted to know how to subtract the required days from the current date.
Like current date is 11/18/2005
required date is 11/15/2005 i.e., subtract 3 days from current date.
Then use that date in our script.
3 years ago
Getting calculation of date is no easy task.
What O/S are you using.
It's inportant because, "echo %Date%" or date /t would produce
different results on different O/S and date formats ie.
WinXP English Date 01/12/2005
WinXP American Date 12/01/2005
Win 2000 the same but adds the Weekday Tue 01/08/2005
3 years ago
You can try the below. it works in XP.
FOR /F "TOKENS=1,2 DELIMS=/ " %%A IN ('DATE /T') DO SET mm=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('DATE /T') DO SET dd=%%B
FOR /F "TOKENS=3* DELIMS=/ " %%A IN ('DATE /T') DO SET yyyy=%%B
set /A dd=%dd%-3
set Pdate=%mm%/%dd%/%yyyy%
echo %Pdate%
rgds
Mahen
9 months ago
3 years ago
Idea about getting the current date time in required format is good. I wanted to know how to subtract the required days from the current date.
Like current date is 11/18/2005
required date is 11/15/2005 i.e., subtract 3 days from current date.
Then use that date in our script.</ul>
Date Calculation In Batch Files XP/2000:
http://www.tech-recipes.com/batch_file_programm...
2 years ago
I am trying to modify your code so it sets a variable for date in the format YYMMDD with no spaces. I tried to make the mods, but I just don't have the knowledge nor the time to figure this out.
Can you assist?
dklock
2 years ago
for /f "tokens=1,2" %%u in ('date /t') do set d=%%v
for /f "tokens=1" %%u in ('time /t') do set t=%%u
if "%t:~1,1%"==":" set t=0%t%
rem set timestr=%d:~6,4%%d:~3,2%%d:~0,2%%t:~0,2%%t:~3,2%
set datestr=%d:~6,4%%d:~0,2%%d:~3,2%
set timestr=%t:~0,2%%t:~3,2%
@echo %datestr%-%timestr%
@echo %datestr%
@echo %timestr%
SparkByte
1 year ago
This is what i use to create the date:
Set DD_MM_YYYY=%DATE:~4,2%_%DATE:~7,2%_%DATE:~10,4%
then create file and add it to name as so:
7a u -tzip e:backupincremental_%DD_MM_YYYY%.zip
I would like to set the initial date for the file on lets say Monday 12_10_2007 then for Tues, Wed, and Thurs, append the file name to something like:
incremental_%DD_MM_YYYY%_%Tues%.zip
incremental_%DD_MM_YYYY%_%Wed%.zip
incremental_%DD_MM_YYYY%_%Thurs%.zip
Is it possible to set tues, wed, thurs as variables then script the rename of the file to reflect the new days?
I guess I'm too new at this and could use some advice.
Thanks,
8 months ago
instead of: DATE/T
6 months ago
6 months ago
:: script for datestring in yyyymmdd format
:: XJ Moonen Netherlands
for /f "tokens=1,2" %%u in ('date /t') do set d=%%v
for /f "tokens=1" %%u in ('time /t') do set t=%%u
if "%t:~1,1%"==":" set t=0%t%
set datestr=%d:~6,4%%d:~3,2%%d:~0,2%
set y=%d:~6,4%
set m=%d:~3,2%
set d=%d:~0,2%
:: test if month < 10 if yes then add a leading zero
if /i %m% LSS 10 set m=0%m%
:: test if day < 10 if yes then add a leading zero
if /i %d% LSS 10 set d=0%d%
set ymd=%y%%m%%d%
::set the actual timestring ie 2034
set timestr=%t:~0,2%%t:~3,2%
:: set the filename
set fname=Filename%ymd%_%timestr%
:: show the filename
echo %fname%
c:\windows\system32\sleep.exe 10
5 months ago
set mydate=%date:~4,2%%date:~7,2%%date:~10,4%
4 months ago
echo Get the current date and time in YYYY-MM-DD-HH-MM-SS format
SET isodt=%date:~10,4%-%date:~7,2%-%date:~4,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%
echo %isodt%
Thanks a million
3 months ago
4 months ago
@echo off
cls
echo Copying started at %date% %time%
xcopy "E:\%date%.DMP" "C:\Documents and Settings\Hp1\Local Settings\Application Data\Microsoft\CD Burning\BACKUP\*.*" /s /e /h /c /d /i /y
xcopy "C:\Documents and Settings\Hp1\Local Settings\Application Data\Microsoft\CD Burning\BACKUP\*.*" "G:\BACKUP\*.*"
PAUSE
explorer g:
4 months ago
4 months ago
ex : myfile20090210
4 months ago
FOR /F "TOKENS=1,2 DELIMS=/ " %%A IN ('DATE /T') DO SET mm=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('DATE /T') DO SET dd=%%B
FOR /F "TOKENS=3* DELIMS=/ " %%A IN ('DATE /T') DO SET yyyy=%%B
set /A dd=%dd%
set Pdate=%yyyy%_%mm%_%dd%
echo %Pdate%
mkdir C:\MYFILE_"%PDATE%"\
2 months ago
that helps
2 months ago
@Echo Off
Set YYYY-MM-DD=%DATE:~6,4%-%DATE:~0,2%-%DATE:~3,2%
2 months ago
2 months ago
echo %date:~10,4%%date:~7,2%%date:~4,2%
ren d:\temp\log.pdf Survey%date:~10,4%%date:~7,2%%date:~4,2%.pdf
pause
for /f "tokens=1-5 delims=:" %%d in ("%time%") do rename "hope.pdf" %%d-%%e.pdf
pause
1 month ago
1 month ago
The %DATE% AND %TIME% variables contain the formated date and time so you an just extract the substrings using regular variable syntax
set _DATETIME=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%
In my case
%DATE% contains "Tue 05/26/2009"
so %DATE:~10,4% means to extract a substring 4 characters long starting from character 10
If you weren't aware of that way of handling substrings for any variables, now you know.
If you have a different default date format than mine you will have to adapt the parameters
1 month ago
@echo off
goto test
:get_date_yyyymmdd
setlocal enableextensions enabledelayedexpansion
set _RV=
set _ERR=0
set _CMD=reg query "HKCU\Control Panel\International" /v sShortDate
for /f "usebackq skip=2 tokens=3,* delims= " %%i in (`%_CMD%`) do (
rem Amsterdam/Houston servers:
rem Short date format (%%i): M/d/yyyy
rem Sample %DATE%: Thu 05/29/2009
rem London servers:
rem Short date format (%%i): dd/MM/yyyy
rem Sample %DATE%: 29/05/2009
set D=!DATE!
echo i: %%i
echo D: !D!
if "%%i"=="M/d/yyyy" (
rem I'm assuming the day abbreviation will always be three chars
rem (so we account for four in total, including the space). So
rem far, I can attest that this is definitely the case on Wed &
rem Thu ;-)
set yyyy=!D:~-4!
set mm=!D:~-10,-8!
set dd=!D:~-7,-5!
) else if "%%i"=="dd/MM/yyyy" (
set yyyy=!D:~-4!
set mm=!D:~-7,-5!
set dd=!D:~-10,-8!
) else (
echo fatal: I don't understand this system's date format (%%i^)
set _ERR=1
)
)
set _RETVAL=!yyyy!!mm!!dd!
endlocal & set _YYYYMMDD=%_RETVAL% & set _ERROR=%_ERR%
exit /b %_ERROR%
:test
call :get_date_yyyymmdd
echo formatted date: %_YYYYMMDD%
1 month ago
I was going to recreate xset32 for win64 in c++ or PERL, but this is much easier.