Computing.Net > Forums > Programming > singular date not showing in this

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

singular date not showing in this

Reply to Message Icon

Original Message
Name: alwaysk2
Date: September 4, 2008 at 14:30:27 Pacific
Subject: singular date not showing in this
OS: Windows 2003 Server
CPU/Ram: 8GHZ/ 16 GB
Manufacturer/Model: IBM
Comment:

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 090208

what do i need to add or edit in this code?

K2™
System/Network Engineer


Report Offensive Message For Removal


Response Number 1
Name: NoIdea
Date: September 4, 2008 at 15:48:22 Pacific
Reply: (edit)

Can you not use?
echo. %date:~-10,2%%date:~-7,2%%date:~-4,4%
Please tell me


Report Offensive Follow Up For Removal

Response Number 2
Name: Judago
Date: September 4, 2008 at 16:37:04 Pacific
Reply: (edit)

The

date /t
command is affected by how you set your date settings in windows. Go to the command line and type
date /t
then 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

Response Number 3
Name: alwaysk2
Date: September 4, 2008 at 16:52:36 Pacific
Reply: (edit)

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 me

I 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

Response Number 4
Name: Judago
Date: September 4, 2008 at 17:01:10 Pacific
Reply: (edit)

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

Response Number 5
Name: NoIdea
Date: September 5, 2008 at 01:04:58 Pacific
Reply: (edit)

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


Response Number 6
Name: Judago
Date: September 5, 2008 at 01:47:12 Pacific
Reply: (edit)

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

Response Number 7
Name: NoIdea
Date: September 5, 2008 at 02:04:02 Pacific
Reply: (edit)

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

Response Number 8
Name: alwaysk2
Date: September 5, 2008 at 09:48:49 Pacific
Reply: (edit)

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

Response Number 9
Name: Judago
Date: September 9, 2008 at 01:46:54 Pacific
Reply: (edit)

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

Response Number 10
Name: alwaysk2
Date: September 9, 2008 at 02:28:08 Pacific
Reply: (edit)

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






Post Locked

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


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History




Data Recovery Software