2

Good day - would anyone be able to assist me with the below query.

Desired result i need would be a directory 25-08-2015-10-15 (dd/mm/yy-hh:mm)

Before 10 am i get a directory like 8-22(hh-mm) after 10 it writes :25-08-2015-10-15 (dd-mm-yy-hh-mm)

Below is my Batch File:

set dd=%DATE:~0,2%
set MM=%DATE:~3,2%
set yy=%DATE:~8,2%
set yyyy=%DATE:~6,4%
set hh=%TIME:~0,2%
set mm=%TIME:~3,2%

mkdir \Makereport\%folderdate%
set folderdate=%date:~0,2%-%date:~3,2%-%date:~6,4%-%time:~0,2%-%time:~3,2%

mkdir \Makereport\%folderdate%

REM copy file to that date/Time
copy \Makereport\*.CSV \Makereport\%folderdate%\

cd %folderdate%
REM 7z.exe location

Path = c:\batch
7z a Retail.zip *.CSV -pRetailPass@
REM Subject Line for Email
mkdir \Makereport\%folderdate%\Retail_%folderdate%
cd..
del *.csv

I have tried to add:

if "%time:~0,1%" == " " (set folderdate=0%time:~1,1%) ELSE set folderdate=%time:~0,2%

echo folderdate=%date:~6%%date:~3,2%%date:~0,2%_%folderdate%%time:~3,2%

But I must be doing something wrong.

jeb
  • 70,992
  • 15
  • 159
  • 202
Bize32
  • 53
  • 6
  • 1
    looks like your time settings are `h:m:s` and you need `hh:mm:ss` – npocmaka Aug 25 '15 at 08:58
  • 1
    to check your time settings run `reg query "HKEY_USERS\.DEFAULT\Control Panel\International"` – npocmaka Aug 25 '15 at 09:01
  • 1
    You should `echo` your `%TIME%` and check the difference for both times – jeb Aug 25 '15 at 09:01
  • Hi Npocmaka The desired result works fine after 10am (dd/mm/yy/hh/mm) before then i only get (hh/mm) - just at my original post (edited) – Bize32 Aug 25 '15 at 09:01
  • 1
    Take a look at [How to get current datetime on Windows command line, in a suitable format for using in a filename?](http://stackoverflow.com/a/203116/3074564) how to get current date and time string with wmic command independent on language settings in a format you want. – Mofi Aug 25 '15 at 09:05
  • Thanks Guys - Ill have a look at all the points made - Many Thanks Npocmaka & Jeb – Bize32 Aug 25 '15 at 09:06
  • Thanks Mofi - i missed that page – Bize32 Aug 25 '15 at 09:07
  • Hi Guys I added @echo off For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b) For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%b-%%a) – Bize32 Aug 25 '15 at 09:20

1 Answers1

0

Add the lower line - I think it should fix an issue where a space is at the start of the time before 10am.

Other solutions exist but this may be the one you are after.

set hh=%TIME:~0,2%
set hh=%hh: =0%
foxidrive
  • 37,659
  • 8
  • 47
  • 67