Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi,
i have found codes which makes a date in mmddyy format here it is :for /f "tokens=2,3,4 delims=/ " %%i in ('date /t') do (
set my_month=%%i
set /A my_day=%%j:~2-1
set my_year=%%k )
set my_year=%my_year:~2,2%
set X=%my_month%%my_day%%my_year%
but the main problem of the above code is it only shows exact date from 10 to 31st of the month. its showing dates from 1 to 9 like 09108 09208 09308 <--- as i need to make it work like 090108 090208 090208what do i need to add or edit in this code?
K2™
System/Network Engineer
The
date /tcommand is affected by how you set your date settings in windows. Go to the command line and typedate /tthen come back and post the format your using.By this I mean does it show an abbreviated day before the date? Do single digit days and months have leading zero's?
I already understand you use month first, followed by day then year.
Report Offensive Follow Up For Removal
hey date /t command shows me
Fri 09/05/2008
and
Can you not use?
echo. %date:~-10,2%%date:~-7,2%%date:~-4,4%
Please tell meI need to make a folder using that date variable dear so i cant use echo
K2™
System/Network Engineer
Report Offensive Follow Up For Removal
Ever so slightly modified....
for /f "tokens=2,3,4 delims=/ " %%i in ('date /t') do (
set my_month=%%i
set my_day=%%j
set my_year=%%k )
set my_year=%my_year:~2,2%
set X=%my_month%%my_day%%my_year%[edit]
NoIdea: in this case it would actually be
%date:~-10,2%%date:~-7,2%%date:~-2%
Report Offensive Follow Up For Removal
OK at the risk of proving really annoying and living up to my appellation.
>YourOutputFolder_%date:~-10,2%.%date:~-7,2%.%date:~-2%.txt
Judago
For me the script produces (obviously its my mistake)
D:\>for /F "tokens=2,3,4 delims=/ " %i in ('date /t') do (
set my_month=%i
set my_day=%j
set my_year=%k
)D:\>(
set my_month=09
set my_day=2008
set my_year=
)D:\>set my_year=
D:\>set X=092008
Is this because of ddmmyy and not mmddyy
Report Offensive Follow Up For Removal
NoIdea,
That's exactly why I asked to see what the output of date /t would be.
To answer your question, Yes and no, I also use day first month second and year last. For some reason some variations like d/mm/yyyy give an abbreviated day of the week at the start e.g fri. Using dd/mm/yyyy on the otherhand doesn't give the day.
If your using XP go to the control panel and open "regional and language settings" their should be a drop down box with <language>(<country>). Beside it their is a "Customise" button clicking it opens a dialog/settings box, Their is a date tab on this box. Once in this tab the short date is the setting of interest.
So of course the batch is settings independent. As it stands to be correct it needs the abbreviated day of the week, forward slashes as separators, a 4 digit year and to be month first day second and year last.Unfortunately the %date% variable has almost exactly the same problem, so it can't be used to avoid the pitfalls of having the date set the way you like it.
Report Offensive Follow Up For Removal
Cheers for that Judago,
I sincerely hope you get some thanks for all your work on Carts.. Batch to edit Batch. You are very good I couldn't even be bothered to read it all!!
Good luck to you always.
Report Offensive Follow Up For Removal
hey thanks a lot all of you.
just one more thing if you could help me out. Now i want this code to work on yesterday's date. i mean when this code runs it will put the date of yesterday. if its is 090508 today than it will put 090408.
thanks once again
K2™
System/Network Engineer
Report Offensive Follow Up For Removal
Will this do you.........
SET MONTH=%DATE:~-10,2%&&SET DAY=%DATE:~-7,2%&&SET YEAR=%DATE:~-4%
IF %DAY% LSS 10 SET DAY=%DAY:~-1%
IF %MONTH% LSS 10 SET MONTH=%MONTH:~-1%
SET /A DAY-=1
IF %DAY%==0 (GOTO LASTMONTH) ELSE GOTO OUTPUT:LASTMONTH
SET /A MONTH-=1
IF MONTH==0 GOTO LASTYEAR
IF NOT %MONTH%==2 GOTO DAYSMON
SET LT=%YEAR%:LEAPFROG
SET /A LT-=4
IF %LT% GEQ 4 GOTO LEAPFROG
IF %LT% GTR 0 (SET DAY=28) ELSE SET DAY=29
GOTO OUTPUT:DAYSMON
FOR %%G IN (1,3,5,7,8,10) DO IF %MONTH%==%%G SET DAY=31&&GOTO OUTPUT
FOR %%H IN (4,6,9,11) DO IF %MONTH%==%%H SET DAY=30&&GOTO OUTPUT:LASTYEAR
SET /A YEAR-=1&&SET DAY=31&&SET MONTH=12:OUTPUT
IF %DAY% LSS 10 SET DAY=0%DAY%
IF %MONTH% LSS 10 SET MONTH=0%MONTH%
ECHO %MONTH%%DAY%%YEAR:~-2%
Report Offensive Follow Up For Removal
VIOLA..... you are great... i luv you for that... thanx a lot for the code.... thanks a millionz...
K2™
System/Network Engineer
Report Offensive Follow Up For Removal
![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |