Cant get date to format folders correctly

October 12, 2009 at 05:31:45
Specs: Windows 2000
I'm having a problem getting the folders to format the time correctly. If i run the bat file anytime in the morning before 10am the folders wont create correctly. So evertime i try to run it when ever i come into work (8am) it doesnt work, it makes random folders where ever the bat file is at.

below is my bat file. i dont know what else to try.


@Echo off
set yymmdd=%date:~10,4%%date:~4,2%%date:~7,2%
set yymmdd_hhmm=%date:~10,4%%date:~4,2%%date:~7,2%%time:~0,2%%time:~3,2%
mkdir F:\%yymmdd%\%yymmdd_hhmm%\%yymmdd_hhmm%_1

See More: Cant get date to format folders correctly

Report •

October 12, 2009 at 05:47:43
Probably because the TIME before 10 has no leading zero.

Helping others achieve escape felicity


Report •

October 12, 2009 at 05:57:25
Ok well were would I change it to have that leading zero at. I'm new to this so don't expect me to know what you're talking about =)


Report •

October 12, 2009 at 06:24:17
I have no idea what your %date% %time% output looks like.
I can't test your batch because my %date% %time% looks
completely different.

I have used your batch just as it is.
So, there might be a few things that you will need to tweak.

@Echo off
set yymmdd=%date:~10,4%%date:~4,2%%date:~7,2%

IF %Time:~0,2% lss 10 (SET
0%Time:~1,1%%Time:~3,2%) ELSE SET


The "IF" Statement is all on one line.

Report •

Related Solutions

October 12, 2009 at 06:45:30
Thanks lantere, that did the trick.

Report •

October 12, 2009 at 07:17:04

That one gave me a few headaches in the past as well.

Just a note:
I am not sure, but I think you might run into a snag if your
Time is set as AM/PM, and if you run this batch file in the
morning and afternoon.
If that happens, try changing the Time to 24 hours.

Report •

Ask Question