To the following value:
"20020314"
Any ideas?
-Perception
Assuming that YOURVAR already contains "03/14/2002", you could do
the following:
set YOURVAR=%YOURVAR:/=%
set YOURVAR=%YOURVAR:~4,4%%YOURVAR:~0,4%
--
u n z i p m y a d d r e s s t o s e n d e - m a i l
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (
set ddate=%%c%%a%%b)
HTH
Clay Calvert
Replace "W" with "L" in email.
>Perception wrote:
>
>> I'm trying to format a variable with the following value:
>> "03/14/2002"
>>
>> To the following value:
>> "20020314"
>>
>> Any ideas?
>> -Perception
>
>Assuming that YOURVAR already contains "03/14/2002", you could do
>the following:
>
> set YOURVAR=%YOURVAR:/=%
> set YOURVAR=%YOURVAR:~4,4%%YOURVAR:~0,4%
Phil
Very nice!
"Phil Robyn" <pro...@uclink.berkzipeley.edu> wrote in message
news:3C913C37...@uclink.berkzipeley.edu...
-Justin
"Clay Calvert" <ccal...@Wanguru.com> wrote in message
news:16f29ucl1uot1sp3b...@4ax.com...
This is how I do it. Problem is, when I move the script to a
different computer, with different system settings, the date format is
different, and my script breaks. i.e. on one Win2K Server I use
%%a/%%b/%%c and on the other Win2K Server I have to use %%c/%%a/%%b in
order to have output yyyy/mm/dd in both cases.
Do any of you have a trick for making this code more portable? I
suppose I could test for the length of %%a, %%b, and %%c, but maybe
there is a more elegant solution.
Regards,
Ron.
Hi Ron,
Here's some flexible code. Add/remove as many date
formats as you like.
-- Ritchie
================ start =============================
@echo off&setlocal
for /f "skip=1 tokens=3-6 delims=:(\-/)" %%a in (
'echo.^|date'
) do (
goto:%%a%%b%%c
)
:yymmdd
echo Get date in yymmdd format
goto:eof
:mmddyy
echo Get date in mmddyy format
goto:eof
:ddmmyy
echo Get date in ddmmyy format
goto:eof
:yyddmm
echo Get date in yyddmm format
goto:eof
=================== end ============================
Hi Ron,
My earlier post got me thinking (for once)...
Version II, which is effectively a one-liner, works on NT/2K
with every date format one could ever reasonably expect to
encounter. This is how I'll be retrieving dates from now on.
================== start getdate.bat =========================
@echo off&setlocal
for /f "skip=1 tokens=3-6 delims=:.(\-/)" %%a in ('echo.^|date') do (
for /f "tokens=2-4 delims=.\-/ " %%d in ('date /t') do (
set %%a=%%d&set %%b=%%e&set %%c=%%f
)
)
echo Month: %mm%
echo Date: %dd%
echo Year: %yy%
================== end getdate.bat ===========================
PS When testing don't forget to start a new cmd.exe after
changing regional settings.
-- Ritchie
Use my NOWMINUS (via sig line 3); it has no interest whatsoever in any
system settings.
It can give the date in the following basic formats (all the same date,
01:02:03) directly :
2001-12-25
2001-52-02
0002452269
1009242123
2001-38-05
2001-09-20
2001-359
Tue, 25 Dec 2001
2001-4-86 4Q01 4Q2001
25-12-2001
For yyyy/mm/dd, use NOWMINUS j/ f1 r
--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS, EXE in <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.txt.
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm &c.
>Hi Ron,
>My earlier post got me thinking (for once)...
>
>Version II, which is effectively a one-liner, works on NT/2K
>with every date format one could ever reasonably expect to
>encounter. This is how I'll be retrieving dates from now on.
>
If you're interested there are a ton of posts on this topic in the
archive - the tricky thing is getting a reliable date that includes a
4 digit year:
http://groups.google.com/groups?selm=3bc48422.942835%40news.demon.co.uk&oe=ISO-8859-1&output=gplain
:: This batch file - based on a previous post by Michael Jerkovic
will return the date (including 4 digit year) into environment vars
:: Works on any NT machine independent of regional date settings
@ECHO off
SETLOCAL
IF [%1]==[] goto s_start
ECHO GETDATE.cmd
ECHO Returns the date independent of regional settings
ECHO Creates the environment variables %v_year% %v_month% %v_day%
ECHO.
ECHO SYNTAX
ECHO GETDATE
ECHO.
ECHO.
GOTO :eof
:s_start
FOR /f "tokens=2-4 skip=1 delims=(-)" %%G IN ('echo.^|date') DO (
FOR /f "tokens=2 delims= " %%A IN ('date /t') DO (
SET v_first=%%G
SET v_second=%%H
SET v_third=%%I
SET v_all=%%A
)
)
SET %v_first%=%v_all:~0,2%
SET %v_second%=%v_all:~3,2%
SET %v_third%=%v_all:~6,4%
ECHO Today is Year: [%yy%] Month: [%mm%] Day: [%dd%]
ENDLOCAL & SET v_year=%yy%& SET v_month=%mm%& SET v_day=%dd%
-
Simon Sheppard
Web: http://www.ss64.com
email: Simon@ "
-
Hi Simon,
If it's to do with NT batch, I'm always interested. By 'archive' do
you mean Google, or is there some another place?
Unless I've misunderstood you, I don't see whats tricky about getting a
4 digit date, as you know its part of the 'date /t' output.
I also considered a solution like yours where the separator character
(SC) is irrelevant, but decided against it as I felt it is more likely
to fail had a user been 'playing around' with the SC.
Reason being, anyone crazy enough to change the SC may just as well have
decided to use more than one character, for example '--' or '~#~',
causing any script that assumed a single SC to fail.
Of course, '~#~' would cause my solution to fail as it stands (although
'--' would be fine), but adding extra characters to my "delims" (omitted
from my OP for clarity) is all that's required.
Taking these arguments to their extreme, one could append all non numeric
characters to the "delims", keeping my solution a one-liner. On the other
hand, a solution that catered for a 1, 2 or 3 character length separator
would require additional coding.
All aspects considered, I maintain my earlier post stands as the
preferred solution.
--
Ritchie
Undo my address for email
>Hi Simon,
>If it's to do with NT batch, I'm always interested. By 'archive' do
>you mean Google, or is there some another place?
>
Yes I mean Google groups - though I guess other sites may be archiving
the newsgroup too
>Unless I've misunderstood you, I don't see whats tricky about getting a
>4 digit date, as you know its part of the 'date /t' output.
fair point - now I've actually tried your code - it does give a 4
digit year
>I also considered a solution like yours where the separator character
>(SC) is irrelevant, but decided against it as I felt it is more likely
>to fail had a user been 'playing around' with the SC.
>Reason being, anyone crazy enough to change the SC may just as well have
>decided to use more than one character, for example '--' or '~#~',
>causing any script that assumed a single SC to fail.
>
>Of course, '~#~' would cause my solution to fail as it stands (although
>'--' would be fine), but adding extra characters to my "delims" (omitted
>from my OP for clarity) is all that's required.
Well multiple character date separators is something I've yet to see
- but yes it would break the previous solution
>
>Taking these arguments to their extreme, one could append all non numeric
>characters to the "delims", keeping my solution a one-liner. On the other
>hand, a solution that catered for a 1, 2 or 3 character length separator
>would require additional coding.
The date formats for different country codes are as follows:
Country or language CountryCode Date format Time format
United States 001 01/23/1997 5:35:00.00p
Czechoslovakia 042 23.01.1997 17:35:00
France 033 23.01.1997 17:35:00 Germany
049 23.01.1997 17:35:00
Latin America 003 23/01/1997 5:35:00.00p
International English 061 23/01/1997 17:35:00.00
Portugal 351 23-01-1997 17:35:00 Finland
358 23.1.1997 17.35.00 Switzerland 041
23.01.97 17 35.00
Norway 047 23.01.97 17:35:00
Belgium 032 23/01/97 17:35:00
Brazil 055 23/01/97 17:35:00 Italy
039 23/01/97 17.35.00
United Kingdom 044 23/01/97 17:35:00.00
Denmark 045 23-01-97 17.35.00
Netherlands 031 23-01-97 17:35:00
Spain 034 3/12/98 17:35:00
Hungary 036 1997.01.23 17:35:00
Canadian-French 002 1997-01-23 17:35:00
Poland 048 1997-01-23 17:35:00 Sweden
046 1997-01-23 17.35.00
Now buried in that lot is finland with 23.1.1997
You might expect this to cause problems - but luckily the date command
ignores this particular format and displays 2 digits regardless.
This was the reason for parsing the DATE output based on character
position - unfortunately DATE isn't smart enough to ignore multiple
character date separators.
>
>All aspects considered, I maintain my earlier post stands as the
>preferred solution.
>
I'll go along with that - it's nice and short - I'd just change the
delims to "delims=\-/." so that all the 'standard' formats above are
covered.
Oh and this isn't going to work under Win95 or DOS - so change the
extension to .cmd to stop them from running it.
================== start getdate.cmd =========================
@echo off&setlocal
for /f "skip=1 tokens=3-6 delims=:.(\-/.)" %%a in ('echo.^|date') do (
for /f "tokens=2-4 delims=.\-/ " %%d in ('date /t') do (
set %%a=%%d&set %%b=%%e&set %%c=%%f
)
)
echo Month: [%mm%]
echo Date: [%dd%]
echo Year: [%yy%]
================== end getdate.cmd ===========================
I've also yet to see a non-standard seperator.
> >All aspects considered, I maintain my earlier post stands as the
> >preferred solution.
> >
> I'll go along with that - it's nice and short - I'd just change the
> delims to "delims=\-/." so that all the 'standard' formats above are
> covered.
It was covered, you've re-written my post with two periods.
> for /f "skip=1 tokens=3-6 delims=:.(\-/.)" %%a in ('echo.^|date') do (
--
Yes, you're absolutely right; the single command will yield the same
result. Nevertheless, the first command is also a nice one to know. :-)
>
> I understand how it works, with :~6,4 meaning use 4 characters beginning
> with an offset of 6, but I can't find any of it documented anywhere, not
> in Help|Reference|MS-DOS Commands anyway. Is it?
Type 'SET /?' (without the apostrophes) at the CMD prompt.
<snip>
>================== start getdate.bat =========================
>@echo off&setlocal
>
>for /f "skip=1 tokens=3-6 delims=:.(\-/)" %%a in ('echo.^|date') do (
> for /f "tokens=2-4 delims=.\-/ " %%d in ('date /t') do (
> set %%a=%%d&set %%b=%%e&set %%c=%%f
> )
>)
>
>echo Month: %mm%
>echo Date: %dd%
>echo Year: %yy%
>
>================== end getdate.bat ===========================
>
One word of caution - on XP, depending on the locale, "date/t" doesn't
always return the Day of the Week as the first token. It's necessary
to take an extra step and check whether the first token is numeric. If
it's not, then the date is in the second token.
@echo off
setlocal
for /f "tokens=1-2" %%a in ('date /t') do (
set date=%%a
set date1=%%b
)
if %date:~0,1% GTR 9 set date=%date1%
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
for /f "tokens=1-3 delims=-/." %%d in ("%date%") do (
set %%a=%%d
set %%b=%%e
set %%c=%%f
)
)
echo Month: %mm%
echo Date: %dd%
echo Year: %yy%
Garry
> One word of caution - on XP, depending on the locale, "date/t" doesn't
> always return the Day of the Week as the first token. It's necessary
> to take an extra step and check whether the first token is numeric. If
> it's not, then the date is in the second token.
Thanks for this info Gary. Can I ask you, in XP, when the DOW is not the
first token, it that because it is another token (presumably the last)
or because it does not appear at all?
And in this scenario, does the same happen with 'echo.^|date', and
what about %date%?
>It was covered, you've re-written my post with two periods.
>
Sorry - I can't believe I posted that - I must have been having an
'off day' yesterday
Anyway I tested this again at work today
The first thing I noticed is that XP outputs the date in a different
format...
C:\>ver
Microsoft Windows XP [Version 5.1.2600]
C:\>date/t
18/03/2002
C:\>echo.|date
The current date is: 18/03/2002
Enter the new date: (dd-mm-yy)
C:\>echo %date%
18/03/2002
So here's a variant of your script adjusted to run under NT, W2k and
XP - all lines indented 3 chars
@echo off&setlocal
for /f "tokens=1-4 delims=/-. " %%G in ('date /t') DO call
:s_fixdate %%G %%H %%I %%J
goto :eof
:s_fixdate
:: Adjust for Win XP
SET/a part1=%1
if %part1% EQU 0 shift
:: Save the day month year
SET part1=%1
SET part2=%2
SET part3=%3
:: Figure out which part is which
for /f "skip=1 tokens=2-4 delims=(-)" %%G in ('echo.^|date') do (
for /f "tokens=1-3" %%U in ("%part1% %part2% %part3%") do (
set %%G=%%U
set %%H=%%V
set %%I=%%W
)
)
::print the resulting date
echo Month: [%mm%]
echo Day: [%dd%]
echo Year: [%yy%]
I have briefly tested this under all 3 platforms with UK, French and
German date formats.
The first SET statement should evaluate any text "Mon, Tue, Wed..." to
0 so we can test for this without knowing or relying on any specific
spelling which may be locale specific.
>One word of caution - on XP, depending on the locale, "date/t" doesn't
>always return the Day of the Week as the first token. It's necessary
>to take an extra step and check whether the first token is numeric. If
>it's not, then the date is in the second token.
>
>@echo off
>setlocal
>for /f "tokens=1-2" %%a in ('date /t') do (
> set date=%%a
> set date1=%%b
>)
>if %date:~0,1% GTR 9 set date=%date1%
>
I don't have XP here to test it but I think this line will fail
if %date:~0,1% GTR 9 set date=%date1%
How can any single character evaluate to > 9 ?
If the first digit is text it will evaluate to 0
I'm tempted to suggest
if %date:~0,1% GTR 0 set...
but of course dates may have a leading zero, so 09 would evaluate to
the same as "Mon"
Hi Simon,
This is really useful that you've posted ALL the date outputs. It
helps illustrate just whats involved trying to code a solution for
all NT o/s's. Nice use of the rarely used SHIFT command in you
solution.
I was playing earlier trying to do a SHIFT on the FOR variables -
no chance.
I actually believe the M$ cmd programmers monitor this group and
have a right laugh. If you're listening guys/gals why not put the
DOW between month and year in the next version?
--
Ritchie
Undo my address for email.
Hi Guys,
If its not a digit, cmd does a string comparison. So it
does have the desired effect. I believe this behaviour is
undocumented and borders on being kinda quirky.
I always code these situations by surrounding the vars
with double quotes thereby 'guaranteeing' the desired
effect and enforcing it to the reader:-
if "%date:~0,1%" GTR "9" set date=%date1%
--
My system is set with the following date time format:
Date output yyyy-mm-dd
Time: HH:mm:ss (24-hr clock).
OUTPUT
C:\>ver
Microsoft Windows XP [Version 5.1.2600]
C:\>date /t
2002-03-18
C:\>echo.|date
The current date is: 2002-03-18
Enter the new date: (yy-mm-dd)
C:\>echo %DATE%
2002-03-18
C:\>time /t
17:56
C:\>echo.|time
The current time is: 17:56:50.79
Enter the new time:
C:\>echo %TIME%
17:57:01.23
"Ritchie Lawrence" <rlaw...@commanddoline.co.uk> wrote in message news:3c966...@mk-nntp-1.news.uk.worldonline.com...
: "Simon Sheppard" <si...@spam.invalid> wrote in message news:3c8a3e6...@news.demon.co.uk...
:
:
>If its not a digit, cmd does a string comparison. So it
>does have the desired effect. I believe this behaviour is
>undocumented and borders on being kinda quirky.
OK I see what it's doing now - this is sort of documented under IF/?
"These comparisons are generic, in that if both string1 and
string2 are both comprised of all numeric digits, then the strings are
converted to numbers and a numeric comparison is performed."
P.S.
A follow on question from all this - how to display the day of week
under XP?
>Thanks for this info Gary. Can I ask you, in XP, when the DOW is not the
>first token, it that because it is another token (presumably the last)
>or because it does not appear at all?
>
>And in this scenario, does the same happen with 'echo.^|date', and
>what about %date%?
>
Actually I don't have XP. The information was supplied by John Gray in
the UK who has done much testing of the various DATE/T, DATE, TIME/T,
TIME and NET TIME output formats for NT/W2k/XP for the myriad of
regional settings.
The bottom line for XP is that the DoW may or may not be present and
if present, may precede or follow the date fields. DATE and DATE/T
will in most, but not all cases, include/exclude the DoW identically
(i.e. if DoW is absent in DATE it will also be absent in DATE/T and
vice versa). If DoW is present, it will be in English in DATE/T but in
the local language in DATE. Nice and consistent huh!
Below is a summary file John produced showing some of the more unusual
formats. I also have the actual output from the date/time commands for
each regional setting if anyone wants a copy.
REGIONAL OPTIONS found in Windows XP Professional, UK English
=============================================================
The results from the commands DATE /T, DATE, TIME/T and TIME for
each of the 93 possible Regional Options differ SO much that it would
be very difficult to describe them. See my file DATETIME.FMT for
examples. Only the names of the Regional Options, Language codes, and
a brief comment are given, where needed.
Language/Country Lang Code
Africaans AFK TIME /T has nm (PM) but no AM
equivalent
Albanian SQI TIME /T has PD (AM) and MD (PM)
Azeri (Cyrillic) AZE
Azeri (Latin) AZE
Basque EUQ
Belarusian BEL
Bulgarian BGR DATE fields followed by two-char DoW
"?."?
Catalan CAT
Croatian HRV
Czech CSY
Danish DAN
Dutch (Belgium) NLB
Dutch (Netherlands) NLD
English (Australia) ENA DoW present in both DATE /T and DATE
English (Belize) ENL
English (Canada) ENC DoW absent in both DATE /T and DATE
English (Caribbean) ENB
English (Ireland) ENI DoW absent in both DATE /T and DATE
English (Jamaica) ENJ
English (New Zealand) ENZ DoW present in both DATE /T and DATE
English (Philippines) ENP
English (South Africa) ENS DoW absent in both DATE /T and DATE
English (Trinidad) ENT
English (United Kingdom) ENG DoW absent in both DATE /T and DATE
English (United States) ENU DoW present in both DATE /T and DATE
English (Zimbabwe) ENW
Estonian ETI
Faroese FOS
Finnish FIN
French (Belgium) FRB
French (Canada) FRC
French (France) FRA
French (Luxembourg) FRA
French (Monaco) FRM
French (Switzerland) FRS
FYRO Macedonian MKI
Galician GLC year value only two digits in DATEs
German (Austria) DEA
German (Germany) DEU
German (Liechtenstein) DEC
German (Luxembourg) DEL
German (Switzerland) DES
Greek ELL
Hungarian HUN yyyy.mm.dd. - note the final full
stop
Icelandic ISL
Indonesian IND
Italian (Italy) ITA
Italian (Switzerland) ITS
Kazakh KKZ
Krygyz (Cyrillic) KYR year value only two digits in DATEs
Latvian LVI yyyy.mm.dd. - note the final full
stop
Lithuanian LTH
Malay (Brunei Darussalam) MSB
Malay (Malaysia) MSL
Mongolian (Cyrillic) MON year value only two digits in DATEs
Norwegian (Bokmal) NOR
Norwegian (Nynorsk) NON
Polish PLK
Portuguese (Brazil) PTB
Portuguese (Portugal) PTG
Romanian ROM
Russian RUS
Serbian (Cyrillic) SRB
Serbian (Latin) SRL
Slovak SKY
Slovenian SLV
Spanish (Argentina) ESS
Spanish (Bolivia) ESB
Spanish (Chile) ESL
Spanish (Columbia) ESO
Spanish (Costa Rica) ESC
Spanish (Dominican Repub.) ESD
Spanish (Ecuador) ESF
Spanish (El Salvador) ESE
Spanish (Guatemala) ESG
Spanish (Honduras) ESH
Spanish (Mexico) ESM
Spanish (Nicaragua) ESI
Spanish (Panama) ESA
Spanish (Paraguay) ESZ
Spanish (Peru) ESR
Spanish (Puerto Rico) ESU
Spanish (Spain) ESP
Spanish (Uruguay) ESY
Spanish (Venezuela) ESV
Swahili SWK
Swedish SVE
Swedish (Finland) SVF
Tatar TTT
Turkish TRK
Ukrainian UKR
Uzbek (Cyrillic) UZB
Uzbek (Latin) UZB
Results from the command NET TIME /DOMAIN (or NET TIME
\\computername)
NET TIME /DOMAIN
Current time at \\ThePDC is m/d/yyyy h:mm xM example: 9/5/2000
5:04 AM
Local time (GMT) at \\ThePDC is m/d/yyyy h:mm xM example: 9/5/2000
11:22 PM
The command completed successfully.
Single letters m, d, or h mean that these values do NOT take leading
zeroes, and so can take 1 or 2 digits.
NOTES
1) The "NET TIME \\machinename" command in Win XP ALWAYS gives date &
time in a variant of the US date and time format, e.g. 5/23/2000 2:07
PM, regardless of the Regional Options.
John Gray 16-23OCT2001, 11-13FEB2002
<Snip>
>P.S.
>A follow on question from all this - how to display the day of week
>under XP?
>-
If the day of week is absent e.g. English (United Kingdom), you have
to do a Day of the Week, Julian Day, Modified Julian Day or similar
calculation to determine the day number, calculate Day No mod 7 to get
the week day number then do a lookup to get the day name. The
following does it based on the Modified Julian Day Number. There are
other similar formulae around.
@echo off
setlocal
set dd=19
set mm=3
set yy=2002
:: Modified Julian Day 0 on 17 Nov, 1858 is a Wednesday
set Days=WedThuFriSatSunMonTue
set /a z=14-mm,z/=12
set /a jy=yy-z
set /a jm=12*z+mm-3
set /a mjd=153*jm+2,mjd/=5
set /a mjd=mjd+dd+365*jy+jy/4-jy/100+jy/400-678882
set /a "DoW=mjd%%7"
set /a DoW*=3
call set DoW=%%Days:~%DoW%,3%%
echo %DoW%
Garry
========================== getdate.cmd ==========================
@echo off&setlocal
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
set %%a=%%d&set %%b=%%e&set %%c=%%f))
echo Year=[%yy%] Month=[%mm%] Date=[%dd%]
=================================================================
If I can find a list of the various regional outputs, I think it
should be possible to get it back to a one-liner.
--
Ritchie
Undo my address for email.
"Simon Sheppard" <si...@spam.invalid> wrote in message news:3c8a3e6...@news.demon.co.uk...
On Tue, 19 Mar 2002 14:37:02 -0000, "Ritchie Lawrence"
<rlaw...@commanddoline.co.uk> wrote:
>Hi All,
>After further deliberation, I now propose the following, for
>retrieving the date on NT/2K/XP, independant of regional
>settings. Anyone care to test it?
>
>========================== getdate.cmd ==========================
>@echo off&setlocal
>
>set t=2&if "%date%z" LSS "A" set t=1
>for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
> for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
> set %%a=%%d&set %%b=%%e&set %%c=%%f))
>
>echo Year=[%yy%] Month=[%mm%] Date=[%dd%]
>=================================================================
>
>If I can find a list of the various regional outputs, I think it
>should be possible to get it back to a one-liner.
>
>--
>Ritchie
Interesting - here's something similar I tested today with a variety
of dates and regional settings under NT/2k/XP
@echo off&setlocal
for /f "tokens=1-4 delims=/-. " %%G in ('date /t') DO call
:s_fixdate %%G %%H %%I %%J
goto :s_print_the_date
:s_fixdate
if "%1:~0,1%" GTR "9" shift
for /f "skip=1 tokens=2-4 delims=(-)" %%G in ('echo.^|date') do (
set %%G=%1&set %%H=%2&set %%I=%3)
goto :eof
:s_print_the_date
echo Month: [%mm%]
echo Day: [%dd%]
echo Year: [%yy%]
-
>NOTES
>1) The "NET TIME \\machinename" command in Win XP ALWAYS gives date &
>time in a variant of the US date and time format, e.g. 5/23/2000 2:07
>PM, regardless of the Regional Options.
>
>John Gray 16-23OCT2001, 11-13FEB2002
>
This may be an easier method - though NET TIME requires the SERVER
service to be running (on %computername% ) the script below only
returns a 2 digit year, and it removes some leading zeros
@echo off&setlocal
FOR /f "tokens=6-9 delims=/ " %%G IN ('NET TIME \\%computername%')
DO (
SET v_mm=%%G
SET v_dd=%%H
SET v_yy=%%I
SET v_time=%%J)
ECHO Today is Year: [%v_yy%] Month: [%v_mm%] Day: [%v_dd%]
Echo The time is [%v_time%]
Year=[2002] Month=[03] Date=[19]
"Simon Sheppard" <si...@spam.invalid> wrote in message news:3c94e4d...@news.demon.co.uk...
: crossposted to microsoft.public.win2000.cmdprompt.admin
>Hi All,
>After further deliberation, I now propose the following, for
>retrieving the date on NT/2K/XP, independant of regional
>settings. Anyone care to test it?
>
>========================== getdate.cmd ==========================
>@echo off&setlocal
>
>set t=2&if "%date%z" LSS "A" set t=1
>for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
> for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
> set %%a=%%d&set %%b=%%e&set %%c=%%f))
>
>echo Year=[%yy%] Month=[%mm%] Date=[%dd%]
>=================================================================
This won't work for NT, only W2k & XP automatically set %date%. For
NT, you need to do a prior FOR .. ('date/t')... to do this.
>
>If I can find a list of the various regional outputs, I think it
>should be possible to get it back to a one-liner.
>
I'll send a copy.
Garry
Hi Garry, you _DIDN'T_ test it then ;)
The other way I was thinking of was the same as that above, but scrap
the first line, and add to the second delims all the characters that
may be used for the DOW. Decided against because I've not been able to
find what abbreviations are used for all DOWs in all regions.
I could just add the whole alphabet, but as the delims is case sensitive,
that would 52 characters and even some regions don't used letters from
the 'standard', so I'll stick with the script above.
>"Garry Deane" <garrydeane_at_yahoo.com.au> wrote in message news:3c97d012...@192.168.0.2...
>> On Tue, 19 Mar 2002 14:37:02 -0000, "Ritchie Lawrence"
>> <rlaw...@commanddoline.co.uk> wrote:
>>
>> >Hi All,
>> >After further deliberation, I now propose the following, for
>> >retrieving the date on NT/2K/XP, independant of regional
>> >settings. Anyone care to test it?
>> >
>> >========================== getdate.cmd ==========================
>> >@echo off&setlocal
>> >
>> >set t=2&if "%date%z" LSS "A" set t=1
>> >for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
>> > for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
>> > set %%a=%%d&set %%b=%%e&set %%c=%%f))
>> >
>> >echo Year=[%yy%] Month=[%mm%] Date=[%dd%]
>> >=================================================================
>>
>> This won't work for NT, only W2k & XP automatically set %date%. For
>> NT, you need to do a prior FOR .. ('date/t')... to do this.
>
>Hi Garry, you _DIDN'T_ test it then ;)
Oops - yeah you're right. Quite neat.
>The other way I was thinking of was the same as that above, but scrap
>the first line, and add to the second delims all the characters that
>may be used for the DOW. Decided against because I've not been able to
>find what abbreviations are used for all DOWs in all regions.
>
>I could just add the whole alphabet, but as the delims is case sensitive,
>that would 52 characters and even some regions don't used letters from
>the 'standard', so I'll stick with the script above.
>
I agree
Garry