Hi,
I tried to filtering just day number from variable %DATE% , but have a problem with date 08.2. and 09.2. . I get error cause 08 and 09 are not valid numbers and so on.
Exist some easy solution how to obtain this value as DEC value ?
THX for any reply.
DATE filtering (08 and 09 get error)
Moderator: DosItHelp
Re: DATE filtering (08 and 09 get error)
Would help to see the code you are using but I would assume you are using SET /A at some point in your script which will cause that error. I can't assume how you are parsing out the date but you can continue to use additional string parsing to remove the leading zero.
Re: DATE filtering (08 and 09 get error)
In the decimal system we need 10 numbers (0,1,2,3,4,5,6,7,8,9).
If the first character a "0" then is in batch files the octal system (0,1,2,3,4,5,6,7).
The result from the variable %date% in the German version is in Example "08.02.2012" (February 08 2012).
variable "d" is for day
variable "m" is for month
variable "y" is for year
dat format: dd.mm.yyyy
For other countries is possible other format please check this and change this.
I will hope that will help you.
If the first character a "0" then is in batch files the octal system (0,1,2,3,4,5,6,7).
The result from the variable %date% in the German version is in Example "08.02.2012" (February 08 2012).
Code: Select all
set dat=08.02.2012
set /a d=100%dat:~0,2% %%100
set /a m=100%dat:~3,2% %%100
set /a y=10000%dat:~6,4% %%10000
variable "d" is for day
variable "m" is for month
variable "y" is for year
dat format: dd.mm.yyyy
For other countries is possible other format please check this and change this.
I will hope that will help you.
-
- Posts: 9
- Joined: 23 Jan 2012 14:45
Re: DATE filtering (08 and 09 get error)
Yes I used SET /A command in script.
solved with this script.....for my region date format (št 09.02.2012)
set sd=%DATE:~3,2%
set /a result=%sd:~0,1%
if %result% equ 0 (set /a rd=%sd:0=%) else (set /a rd=%sd%)
echo %rd%
THX for advices to both
but don´t understand what does it means that 100 and %%100 at the start and end of variable....but it looks as much easier solution that I wrote
finally..I changed date format to 09.02.2012 and use this solution
:
set /a d=100%date:~0,2% %%100
solved with this script.....for my region date format (št 09.02.2012)
set sd=%DATE:~3,2%
set /a result=%sd:~0,1%
if %result% equ 0 (set /a rd=%sd:0=%) else (set /a rd=%sd%)
echo %rd%
THX for advices to both

but don´t understand what does it means that 100 and %%100 at the start and end of variable....but it looks as much easier solution that I wrote

finally..I changed date format to 09.02.2012 and use this solution

set /a d=100%date:~0,2% %%100
Re: DATE filtering (08 and 09 get error)
arithmetic operator. You are getting the remainder of the Division which will be your number without the leading zero.
So if your day of the week is 08 the code is prefixing that with 100 so that the number is actually 10008.
Then 10008 is being divided by 100 but by using the % signs it will return the modulus(remainder) of the division.
10008 / 100 = 100 but the remainder is 8. So it assigns 8 to the variable because it is using the % sign. If you used the / it would have assigned 100 to the variable.
So if your day of the week is 08 the code is prefixing that with 100 so that the number is actually 10008.
Then 10008 is being divided by 100 but by using the % signs it will return the modulus(remainder) of the division.
10008 / 100 = 100 but the remainder is 8. So it assigns 8 to the variable because it is using the % sign. If you used the / it would have assigned 100 to the variable.
-
- Posts: 9
- Joined: 23 Jan 2012 14:45
Re: DATE filtering (08 and 09 get error)
OK..I understood...thx for explanation 
keep it up...great forum

keep it up...great forum
