1.

Solve : Decypher file attribute in a FOR loop?

Answer»

My tests on the attribute variable seemed to work but I will give your suggestion a try.

Code: [Select]if %mm% GTR 01 set /a jd1=%jd1%+31
I am creating two dates in the format yyyyddd. I start by taking the year and multiplying by 1000. Then I have to add DAYS based on the month. If the month is March then I need to add the days for January and February. Then I add the day for the date in question.

For eample, suppose the date is 03/15/2009. I take the year and multiply by 1000 getting 2009000. The month is greater than 1 so I add 31 days for January. The month is greater than 2 so I add 28 days for February (yes, I do not account for leap year). The month is not greater than 3 so it falls through the rest of the "if" statements. I then add the current day. Now the date is 2009074.

The "if" statement for greater than 12 will never be true and should be deleted.



QUOTE from: kwc1059

I am creating two dates in the format yyyyddd. I start by taking the year and multiplying by 1000

You may find these SCRIPTS useful

http://www.commandline.co.uk/cmdfuncs/dandt/index.html

Also, VBscript has built in date MATH functions. You can USE them from batch, if VBscripts are allowed on your system

Code: [Select]@echo off

REM Create VBscript
echo wsh.echo Year(wscript.arguments(0))^&DatePart("y", wscript.arguments(0))>Daynumber.vbs

REM now you can use it in your script as many times as you want

set querydate1=20/11/2009

REM pass the date to the VBscript & get back the result
for /f "delims==" %%D in ('cscript //nologo Daynumber.vbs %querydate1%') do set Daynumber1=%%D

set querydate2=20/03/2009

for /f "delims==" %%D in ('cscript //nologo Daynumber.vbs %querydate2%') do set Daynumber2=%%D

echo The day number of %querydate1% is %Daynumber1%
echo The day number of %querydate2% is %Daynumber2%

output

Code: [Select]The day number of 20/11/2009 is 2009324
The day number of 20/03/2009 is 200979
As you can see, my system uses the European dd/mm/yyyy format for dates but I believe that if your system locale settings are US you would find that 11/19/2009 would give you 2009323 but you would have to try that yourself.

Hello


Discussion

No Comment Found