PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

CMDprompt date format issue

 
 
=?Utf-8?B?dmluY2U=?=
Guest
Posts: n/a
 
      4th Oct 2006
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.
 
Reply With Quote
 
 
 
 
foxidrive
Guest
Posts: n/a
 
      4th Oct 2006
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%

 
Reply With Quote
 
=?Utf-8?B?dmluY2U=?=
Guest
Posts: n/a
 
      4th Oct 2006
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%
>
>

 
Reply With Quote
 
foxidrive
Guest
Posts: n/a
 
      4th Oct 2006
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%
>>
>>

 
Reply With Quote
 
=?Utf-8?B?dmluY2U=?=
Guest
Posts: n/a
 
      4th Oct 2006
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%
> >>
> >>

>

 
Reply With Quote
 
Mark V
Guest
Posts: n/a
 
      4th Oct 2006
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.


 
Reply With Quote
 
billious
Guest
Posts: n/a
 
      4th Oct 2006

"vince" <(E-Mail Removed)> wrote in message
news:0A21A6F2-F8C9-4EA6-9037-(E-Mail Removed)...
> "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.


 
Reply With Quote
 
Matt Williamson
Guest
Posts: n/a
 
      4th Oct 2006
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" <(E-Mail Removed)> wrote in message
news:8DFCDA27-EA7E-4FFC-9832-(E-Mail Removed)...
> 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

 
Reply With Quote
 
janders981
Guest
Posts: n/a
 
      17th Dec 2009
If Regional Date format setting is m/d/yy or similar (note yy option) these
examples discussed of Date/t and %date% fail. These examples are fine when
Regional Date format setting is m/d/yyyy or similar (note yyyy option). How
do I get guaranteed for digit year using MS-Dos? Thanks

"Matt Williamson" wrote:

> 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" <(E-Mail Removed)> wrote in message
> news:8DFCDA27-EA7E-4FFC-9832-(E-Mail Removed)...
> > 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
>
>

 
Reply With Quote
 
foxidrive
Guest
Posts: n/a
 
      17th Dec 2009
On Wed, 16 Dec 2009 19:35:01 -0800, janders981
<(E-Mail Removed)> wrote:

>If Regional Date format setting is m/d/yy or similar (note yy option) these
>examples discussed of Date/t and %date% fail. These examples are fine when
>Regional Date format setting is m/d/yyyy or similar (note yyyy option). How
>do I get guaranteed for digit year using MS-Dos? Thanks




:: DateTime - WMIC
@echo off
:: info based on usenet post by (E-Mail Removed)
:: 18 Aug 2008 22:29:38 +0100,
:: xp and higher

(
Wmic Path Win32_LocalTime Get day,hour,minute,month,second,year /value
)>%temp%.\wmicinfo.txt
for /f "delims=" %%a in ('type %temp%.\wmicinfo.txt') do set %%a
del %temp%.\wmicinfo.txt
set Day=00%day%
set Hour=00%hour%
set Minute=00%minute%
set Month=00%month%
set Second=00%second%
set Day=%day:~-2%
set Hour=%hour:~-2%
set Minute=%minute:~-2%
set Month=%month:~-2%
set Second=%second:~-2%
set yr=%year:~2%

echo Hour=%hour%
echo Minute=%minute%
echo Second=%second%
echo Day=%day%
echo Month=%month%
echo Year=%year%
echo Yr=%yr%
pause

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help....Date Format issue SandyW Microsoft Excel Misc 1 7th Jan 2009 07:29 PM
Re: Date format issue Douglas J. Steele Microsoft Access VBA Modules 0 6th Dec 2006 08:36 PM
Re: Date format issue Douglas J. Steele Microsoft Access VBA Modules 0 6th Dec 2006 08:05 PM
[Newbie UK Date problem] Ways atround this UK date format localisation/SQLselection issue? DC Microsoft ASP .NET 5 1st Jul 2005 10:35 PM
[Newbie UK Date problem] Ways atround this UK date format localisation/SQLselection issue? DC Microsoft C# .NET 5 1st Jul 2005 10:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:47 PM.