Help with Batch Date

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
slem
Posts: 3
Joined: 11 Jul 2014 07:40

Help with Batch Date

#1 Post by slem » 11 Jul 2014 07:51

rar C:\Backup\testBackup-%date:~-10,2%-%date:~-7,2%-%date:~-4,4%.rar c:\inetpub

currently when WinRAR creates the backup.rar the date format shows as 12/12/12 I would rather if it was Jan-12-2012


an help would be appreciated.


thanks in advance

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help with Batch Date

#2 Post by foxidrive » 11 Jul 2014 08:03

slem wrote:rar C:\Backup\testBackup-%date:~-10,2%-%date:~-7,2%-%date:~-4,4%.rar c:\inetpub

currently when WinRAR creates the backup.rar the date format shows as 12/12/12 I would rather if it was Jan-12-2012



12th dec 2012, Jan 12 2012

The current date is in July 2014. How do you get your dates?

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Help with Batch Date

#3 Post by Squashman » 11 Jul 2014 08:18

Not too mention that it is a lot easier to work with dates in file names when they are formatted YYYY-MM-DD as the dir command does not sort file names logically like Windows Explorer does.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help with Batch Date

#4 Post by foxidrive » 11 Jul 2014 08:28

+1 That's a tip worth taking notice of, if you need to handle your files with a command prompt.

slem
Posts: 3
Joined: 11 Jul 2014 07:40

Re: Help with Batch Date

#5 Post by slem » 11 Jul 2014 08:39

I understand, the date was just an example, but would be nice to have the month as a 3 letter format

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help with Batch Date

#6 Post by foxidrive » 11 Jul 2014 08:51

See if this helps you - it provides three variables that you can use, and change.

Code: Select all

@echo off &setlocal
copy nul "%TEMP%\~.ddf" >nul
makecab /D RptFileName="%TEMP%\~.rpt" /D InfFileName="%TEMP%\~.inf" -f "%TEMP%\~.ddf">nul
for /f "tokens=3-7" %%a in ('find /i "makecab"^<"%TEMP%\~.rpt"') do (
   set "current-date=%%e-%%b-%%c"
   set "current-time=%%d"
   set "weekday=%%a"
)
del /q "%TEMP%\~.*"
echo %weekday% %current-date% %current-time%
pause

slem
Posts: 3
Joined: 11 Jul 2014 07:40

Re: Help with Batch Date

#7 Post by slem » 11 Jul 2014 09:35

that works perfect, just did a few adjustments, and voila, thank you for the help,

Post Reply