Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Batch loop?

Featured Replies

Using the Command Prompt (CMD.EXE) in Win XP Home SP2. Date format is Day mm/dd/yyyy

I want to be able to display the name of the current month using a batch file. The relevant part of the file is:

@echo off

cls

set datemonth=%date:~4,2%

if %datemonth%==11 set datename=Nov

echo %datemonth% %datename%

But do I need 12 'if' statements to handle each of the 12 months or is there a better way with a loop or some kind of array?

Thanks


  • Author

Thank you for your speedy response.

Abject apologies for posting in the wrong forum.

I cannot get your coding to run, the first line gives me the error "Invalid number. Number constants are either decimal (17) hexadecimal (0x11) or octal (021)."

At my knowledge level I can't figure out what the problem is or, obviously, how to correct it. However I have been able to slightly modify your second line in order to get the file to run. Regrettably I function on the KISS principle.

Edited by Yzöwl
code removed

  • Author

With regard to the error message I found this on another site.

You're using "set /a" which will mean any time you try to set a value of "08", or "09" then an error will be thrown, such as this:

Invalid number. Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).

This is because "set /a" will treat any number with a leading 0 as octal, which it will attempt to store as decimal. Obviously "08" and "09" are not value numbers in octal, hence the above error.

Hope it's some help.

I don't know why you are getting an error message.

You stated that you are getting the output mm/dd/yyyy. The code parses your date to give you the first two tokens, using your stated / as a delimiter that means it would set %? as mm i.e. 11 which as you know doesn't have a leading 0.

However, as you will note by my code, to prevent an error of the type you are getting I have already built in a fix. When your run the code in March, the %? variable would be 03. In order to remove any leading 0, I prefix a 1 thus making it 103 then subtract 100 making it read 3! SET/A would therefore never see a figure with a leading 0.

  • Author

Thank you again, things are a bit clearer now.

I stated that the output I'm getting is Day mm/dd/yyyy so the 12th November would show as

"Mon 11/12/2007" without the double quotes. Could it be that %? is being set to "Mon 11" ?

Edited by RatPack

  • Author

Thank you, all is clear now.

Your help is much appreciated.

set datemonth=%date:~4,2%

I did not know that you could extract part of an environment variable with :~x,y. This will be really useful. Also, I did not know about %date% nor %time%, either.

For example, I noticed that

echo %logonserver:~2%

returns the server name, without the two backslashes.

Very interesting!

-John

set datemonth=%date:~4,2%

I noticed that

echo %logonserver:~2%

returns the server name, without the two backslashes.

Also bear in mind that so does this!
echo %logonserver:\=%

Nice tip.

Is there a web page that discusses these type of features in depth?

Thanks,

-John

Nice tip.

Is there a web page that discusses these type of features in depth?

Thanks,

-John

The "base" references are usually:

Rob van der Woude site:

http://www.robvanderwoude.com/

The part about variable expansion/substitution is on the pages related to SET and FOR, check also the SETLOCAL one.

http://www.robvanderwoude.com/variableexpansion.html

http://www.robvanderwoude.com/ntset.html

http://www.robvanderwoude.com/local.html

the SS64 help for windows commands:

http://www.ss64.com/nt/

jaclaz

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.