View Full Version : CMDprompt date format issue


vince
10-04-2006, 10:09 AM
Hello,

Running Windows 2000 SP4. Regional setting on both Short and Long date are
set to dd/MM/yyyy

In command prompt, when entering echo %date% it gives
Wed 04/10/2006

Is there a way to get rid of the Wed (day part), I just want the dd/MM/yyyy

On XP SP1 or SP2 are fine, the date display correctly. The problem is
causing havoc on our application passing the date info.

foxidrive
10-04-2006, 10:22 AM
On Wed, 4 Oct 2006 02:09:02 -0700, vince wrote:

> Hello,
>
> Running Windows 2000 SP4. Regional setting on both Short and Long date are
> set to dd/MM/yyyy
>
> In command prompt, when entering echo %date% it gives
> Wed 04/10/2006
>
> Is there a way to get rid of the Wed (day part), I just want the dd/MM/yyyy

echo %date:~4%

vince
10-04-2006, 10:49 AM
Foxidrive,

How can I set this permanently or at least using script. We only have 5-6
of these windows 2000 machine that have this problem.

Thanks,

"foxidrive" wrote:

> On Wed, 4 Oct 2006 02:09:02 -0700, vince wrote:
>
> > Hello,
> >
> > Running Windows 2000 SP4. Regional setting on both Short and Long date are
> > set to dd/MM/yyyy
> >
> > In command prompt, when entering echo %date% it gives
> > Wed 04/10/2006
> >
> > Is there a way to get rid of the Wed (day part), I just want the dd/MM/yyyy
>
> echo %date:~4%
>
>

foxidrive
10-04-2006, 11:13 AM
On Wed, 4 Oct 2006 02:49:01 -0700, vince wrote:

> How can I set this permanently or at least using script. We only have 5-6
> of these windows 2000 machine that have this problem.

Show me your script and I'll take a look.

> Thanks,

yw.

> "foxidrive" wrote:
>
>> On Wed, 4 Oct 2006 02:09:02 -0700, vince wrote:
>>
>>> Hello,
>>>
>>> Running Windows 2000 SP4. Regional setting on both Short and Long date are
>>> set to dd/MM/yyyy
>>>
>>> In command prompt, when entering echo %date% it gives
>>> Wed 04/10/2006
>>>
>>> Is there a way to get rid of the Wed (day part), I just want the dd/MM/yyyy
>>
>> echo %date:~4%
>>
>>

vince
10-04-2006, 11:44 AM
Foxidrive,

I was hoping you know some set command, I don't have any script at hand.

Any help, greatly apprecaited.

V

"foxidrive" wrote:

> On Wed, 4 Oct 2006 02:49:01 -0700, vince wrote:
>
> > How can I set this permanently or at least using script. We only have 5-6
> > of these windows 2000 machine that have this problem.
>
> Show me your script and I'll take a look.
>
> > Thanks,
>
> yw.
>
> > "foxidrive" wrote:
> >
> >> On Wed, 4 Oct 2006 02:09:02 -0700, vince wrote:
> >>
> >>> Hello,
> >>>
> >>> Running Windows 2000 SP4. Regional setting on both Short and Long date are
> >>> set to dd/MM/yyyy
> >>>
> >>> In command prompt, when entering echo %date% it gives
> >>> Wed 04/10/2006
> >>>
> >>> Is there a way to get rid of the Wed (day part), I just want the dd/MM/yyyy
> >>
> >> echo %date:~4%
> >>
> >>
>

Mark V
10-04-2006, 12:09 PM
In microsoft.public.win2000.cmdprompt.admin =?Utf-8?B?dmluY2U=?=
wrote:

> Hello,
>
> Running Windows 2000 SP4. Regional setting on both Short and
> Long date are set to dd/MM/yyyy

Not your answer, but I strongly suggest Date be formatted in an ISO-
compliant and worldwide understandable format such as:
YYYY-MM-DD
which also make sorting by date and date math much easier.

> In command prompt, when entering echo %date% it gives
> Wed 04/10/2006
>
> Is there a way to get rid of the Wed (day part), I just want the
> dd/MM/yyyy
>
> On XP SP1 or SP2 are fine, the date display correctly. The
> problem is causing havoc on our application passing the date
> info.

billious
10-04-2006, 12:58 PM
"vince" <vince@discussions.microsoft.com> wrote in message
news:0A21A6F2-F8C9-4EA6-9037-03AF2F7E46B8@microsoft.com...
> "foxidrive" wrote:
>
>> On Wed, 4 Oct 2006 02:49:01 -0700, vince wrote:
>>> "foxidrive" wrote:
>>>
>>>> On Wed, 4 Oct 2006 02:09:02 -0700, vince wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> Running Windows 2000 SP4. Regional setting on both Short and Long
>>>>> date are
>>>>> set to dd/MM/yyyy
>>>>>
>>>>> In command prompt, when entering echo %date% it gives
>>>>> Wed 04/10/2006
>>>>>
>>>>> Is there a way to get rid of the Wed (day part), I just want the
>>>>> dd/MM/yyyy
>>>>
>>>> echo %date:~4%
>>>>
>>
>> > How can I set this permanently or at least using script. We only have
>> > 5-6
>> > of these windows 2000 machine that have this problem.
>>
>> Show me your script and I'll take a look.
>>
>>> Thanks,
>>
>> yw.
>>
> Foxidrive,
>
> I was hoping you know some set command, I don't have any script at hand.
>
> Any help, greatly apprecaited.
>
> V
>

Essentially, you can't.

%date% and %time% are set up by the OS and evaluated at the time of
execution. You CAN set an environment variable "date" (or "time") to
anything you want, and this value then overrides the "system" value until
the USER value is deleted (set to null) but I don't think that helps too
much here..

Here's a demo using "time" (which has a habit of changing faster than
"date") :

----- batch begins -------
[1]@echo off
[2]for /l %%i in (1,1,3) do echo %time%&call :later
[3]for /f "tokens=1,2" %%i in ( ' date /t ' ) do if [%%j]==[] (set yds=%%i)
else (set yds=%%j)
[4]echo %yds%
[5]goto :eof
[6]
[7]:later
[8]echo time is %time%
[9]:: set time=user
[10]echo time is %time%
[11]ping -n 2 127.0.0.1 >nul
[12]goto :eof
------ batch ends --------

Lines start [number] - any lines not starting [number] have been wrapped
and should be rejoined. The [number] that starts the line should be removed

The label :eof is defined in NT+ to be end-of-file but MUST be expressed
as :eof

The spaces surrounding the single-quotes are for emphasis only. The SPACES
are not required but the single-quotes ARE required.


With this demo, with line [9] as a comment, and [11] is a 2-second delay,
there are three reports of 3 lines each
* original-time when [2] was commenced
* time when [8] is executed
* time when [10] is executed

This demonstrates that [2] produces the parse-time value (a well-established
principle) and shows that indiscriminate use of %time% (and by extension,
%date%) can cause problems because it CAN change within a script.

If you then take the leading "::" from line [9] then the report changes:
* original-time when [2] was commenced
* time when [8] is executed
* user
* original-time when [2] was commenced
* user
* user
* original-time when [2] was commenced
* user
* user

which shows that the environment value set by the USER overrides that
supplied by the system.

Note however that [3] will correctly set YDS (your Date String) to the
correct value, regardless of whether the format had a leading dayname.

Hence [3] may be used on both XP and 2K (restoring commonality) to establish
the date-string to be used; possibly by substituting "date" for "yds" OR by
using "%yds%" in place of "%date%" in your batches - provided [3] is
executed at the start of each %date%-using batch. "yds" naturally can be
any variable-name you choose.

Matt Williamson
10-04-2006, 04:55 PM
Vince

I use Ritchie Lawrence's GetDate routine for this issue. It returns the date
in whatever format you want. For your example, this will get you what you
want.

@echo off & setlocal
call :GetDate y m d
echo %m%/%d%/%y%
goto :eof

:GetDate yy mm dd
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))
endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF



"vince" <vince@discussions.microsoft.com> wrote in message
news:8DFCDA27-EA7E-4FFC-9832-CD95BCFE8342@microsoft.com...
> Hello,
>
> Running Windows 2000 SP4. Regional setting on both Short and Long date
> are
> set to dd/MM/yyyy
>
> In command prompt, when entering echo %date% it gives
> Wed 04/10/2006
>
> Is there a way to get rid of the Wed (day part), I just want the
> dd/MM/yyyy
>
> On XP SP1 or SP2 are fine, the date display correctly. The problem is
> causing havoc on our application passing the date info.



--
Posted via a free Usenet account from http://www.teranews.com