Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help removing leading day from DATE

64 views
Skip to first unread message

Saucer Man

unread,
Apr 11, 2016, 4:56:36 PM4/11/16
to
I am trying to remove the day from %DATE%.

SET MYDATE = %date%
SET MYDATE = %MYDATE:/=-%

This will give me, for example, Sun 04-10-2016. How do I remove the
"Sun"? I want to keep the space in front of the 04.

foxidrive

unread,
Apr 11, 2016, 5:19:49 PM4/11/16
to
Give this a crack:

@echo off
for %%a in (%MYDATE:/=-%) do set date2= %%a

Zaidy036

unread,
Apr 11, 2016, 8:35:14 PM4/11/16
to
%DATE:~3%

petu...@googlemail.com

unread,
Apr 12, 2016, 7:17:43 AM4/12/16
to
SET "MYDATE=%DATE:~-10%"

petu...@googlemail.com

unread,
Apr 12, 2016, 11:40:18 AM4/12/16
to
Then you do your maipulation...

SET "MYDATE= %MYDATE:/=-%"

Kerr Mudd-John

unread,
Apr 13, 2016, 9:06:44 AM4/13/16
to
or set your date format up front; mine is yyyy-mm-dd

--
Bah, and indeed, Humbug

Saucer Man

unread,
Apr 13, 2016, 5:21:56 PM4/13/16
to
Thank you everyone for your help!

pro...@berkeley.edu

unread,
Apr 13, 2016, 6:13:26 PM4/13/16
to
I like foxidrive's suggestion the best. In fact, you can
even get rid of your first 'set MYDATE' statement. Here's
what it looks like at the CMD prompt:

>for %a in (%date:/=-%) do set mydate=%a

>set mydate=Wed

>set mydate=04-13-2016

If you wanted some space, then insert some space before '%a':

>for %a in (%date:/=-%) do set mydate= %a

>set mydate= Wed

>set mydate= 04-13-2016

Way to go, foxidrive!

--
Phil Robyn



Kerr Mudd-John

unread,
Apr 14, 2016, 5:23:35 PM4/14/16
to
On Wed, 13 Apr 2016 23:13:25 +0100, <pro...@berkeley.edu> wrote:

> On Wednesday, April 13, 2016 at 2:21:56 PM UTC-7, Saucer Man wrote:
>> On 4/11/2016 4:56 PM, Saucer Man wrote:
>> > I am trying to remove the day from %DATE%.
>> >
>> > SET MYDATE = %date%
>> > SET MYDATE = %MYDATE:/=-%
>> >
>> > This will give me, for example, Sun 04-10-2016. How do I remove the
>> > "Sun"? I want to keep the space in front of the 04.
>>
>> Thank you everyone for your help!
>
> I like foxidrive's suggestion the best. In fact, you can
> even get rid of your first 'set MYDATE' statement. Here's
> what it looks like at the CMD prompt:
>
>> for %a in (%date:/=-%) do set mydate=%a
>
>> set mydate=Wed
>
>> set mydate=04-13-2016

In which case a "simpler" way is just:

for %a in (%date%) do set mydate=%a


>
> If you wanted some space, then insert some space before '%a':
>
>> for %a in (%date:/=-%) do set mydate= %a
>
>> set mydate= Wed
>
>> set mydate= 04-13-2016
>
> Way to go, foxidrive!
>
> --
> Phil Robyn
>
>
>


Tom Del Rosso

unread,
Apr 16, 2016, 10:43:51 AM4/16/16
to
Does that have an advantage over this...

SET MYDATE = %date:/=-%
SET MYDATE = %MYDATE:~3%

I find the FOR command is always slow.


Todd Vargo

unread,
Apr 16, 2016, 10:10:30 PM4/16/16
to
The space following the variable name is significant and becomes part of
the name. In the example above, the second SET command would clear the
variable because the space is omitted in the name on the right side.



i.e. the second SET command should be...

SET MYDATE = %MYDATE :~3%



And every use thereafter would have to include the space as well to
return its value.



echo %MYDATE %




>
> I find the FOR command is always slow.

Slow in what way?

Note, the FOR command iterates through a complete list. So if for
example, you use it to search a long list and find what what you need
early in the list, the FOR command still iterates through the entire
list to the end.

Other than that, can you provide an example where FOR is slow for you?

Tom Del Rosso

unread,
Apr 18, 2016, 8:41:24 PM4/18/16
to
Todd Vargo wrote:
> On 4/16/2016 10:43 AM, Tom Del Rosso wrote:
>> foxidrive wrote:
>>> On 12/04/2016 06:56, Saucer Man wrote:
>>>> I am trying to remove the day from %DATE%.
>>>>
>>>> SET MYDATE = %date%
>>>> SET MYDATE = %MYDATE:/=-%
>>>>
>>>> This will give me, for example, Sun 04-10-2016. How do I remove
>>>> the "Sun"? I want to keep the space in front of the 04.
>>>>
>>>
>>> Give this a crack:
>>>
>>> @echo off
>>> for %%a in (%MYDATE:/=-%) do set date2= %%a
>>
>> Does that have an advantage over this...
>>
>> SET MYDATE = %date:/=-%
>> SET MYDATE = %MYDATE:~3%
>
> The space following the variable name is significant and becomes part
> of the name. In the example above, the second SET command would clear
> the variable because the space is omitted in the name on the right
> side.

I copied the OP's lines and modified them. I didn't even notice the
spaces. If you noticed them you should warn the OP about it, because
it's another reason his original code wouldn't work.


> i.e. the second SET command should be...
>
> SET MYDATE = %MYDATE :~3%

I would say it should be this:
SET MYDATE=%MYDATE:~3%

I shouldn't have been too lazy to retype it, but I just did it again.


>> I find the FOR command is always slow.
>
> Slow in what way?
>
> Note, the FOR command iterates through a complete list. So if for
> example, you use it to search a long list and find what what you need
> early in the list, the FOR command still iterates through the entire
> list to the end.
>
> Other than that, can you provide an example where FOR is slow for you?

It's not just that it iterates the complete list. If you filter the
command output with FIND inside of FOR's parentheses, then the external
FIND command has to be loaded and it reads the complete output, and
passes a few lines to FOR. This runs faster in every script I've done
it.


foxidrive

unread,
Apr 19, 2016, 1:47:26 AM4/19/16
to
On 19/04/2016 10:41, Tom Del Rosso wrote:
> It's not just that it iterates the complete list. If you filter the
> command output with FIND inside of FOR's parentheses, then the external
> FIND command has to be loaded and it reads the complete output, and
> passes a few lines to FOR. This runs faster in every script I've done
> it.

There's a situation with FOR that can cause long delays and is exponential.

When reading over a certain amount of data in a FOR /F then this begins to
be a large problem, until it can sit for 5, 10, 15, 45 minutes before any
processing begins.

The number of files, coupled with the length of the filenames being parsed,
is a trigger for this bug.

In normal use a FOR is blindingly quick for me. Well, as blindingly quick
batch scripts are.




Todd Vargo

unread,
Apr 20, 2016, 9:43:54 PM4/20/16
to
On 4/18/2016 8:41 PM, Tom Del Rosso wrote:
> Todd Vargo wrote:
>> On 4/16/2016 10:43 AM, Tom Del Rosso wrote:
>>> foxidrive wrote:
>>>> On 12/04/2016 06:56, Saucer Man wrote:
>>>>> I am trying to remove the day from %DATE%.
>>>>>
>>>>> SET MYDATE = %date%
>>>>> SET MYDATE = %MYDATE:/=-%
>>>>>
>>>>> This will give me, for example, Sun 04-10-2016. How do I remove
>>>>> the "Sun"? I want to keep the space in front of the 04.
>>>>>
>>>>
>>>> Give this a crack:
>>>>
>>>> @echo off
>>>> for %%a in (%MYDATE:/=-%) do set date2= %%a
>>>
>>> Does that have an advantage over this...
>>>
>>> SET MYDATE = %date:/=-%
>>> SET MYDATE = %MYDATE:~3%
>>
>> The space following the variable name is significant and becomes part
>> of the name. In the example above, the second SET command would clear
>> the variable because the space is omitted in the name on the right
>> side.
>
> I copied the OP's lines and modified them. I didn't even notice the
> spaces. If you noticed them you should warn the OP about it, because
> it's another reason his original code wouldn't work.

That was my purpose for posting it to this thread with OP's text intact.
I don't send personal emails to warn OPs about their code errors.

>
>
>> i.e. the second SET command should be...
>>
>> SET MYDATE = %MYDATE :~3%
>
> I would say it should be this:
> SET MYDATE=%MYDATE:~3%

Sure, but you would also need to remove the spaces from the preceding
line as well. Hopefully, OP is still reading to pick up on these tidbits.


0 new messages