Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 175 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create a folder with name as current date in batch (.bat) files

#11
This works for me, try:

ECHO %DATE:~7,2%_%DATE:~4,2%_%DATE:~12,2%
Reply

#12

[To see links please register here]

foxidrive's answer helped me get the folder with the date and time I wanted. I would like to share this method here since it worked great for me and I think it could help other people too, regardless of their locale.


rem The four lines below will give you reliable YY DD MM YYYY HH Min Sec MS variables in XP Pro and higher.

for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%" & set "MS=%dt:~15,3%"

set "dirname=%YYYY%-%MM%-%DD% %HH%-%Min%-%Sec%"

:: remove echo here if you like
echo "dirName"="%dirName%"
Reply

#13
Thanks for the info all, very helpful. I needed something that could create "backup" folder as often as every minute in the same directory, as well as call on it later in the script. Here's what I came up with:

@ echo off

CD %userprofile%\desktop

SET Datefolder="%DATE:~4,2%-%DATE:~7,2%-%DATE:~12,2%_%time:~1,1%%time:~3,2%"

MD "%Datefolder%"

This gives me a folder on the currently logged on user's desktop named: mm-dd-yy_hmm (hour minute minute) ie: 07-28-15_719
Reply

#14
I am sitting in exactly the same boat as you as soon as i am AM before 10 i cannot use the below, i have set my time from 12hr to 24 hr, changed hh/mm to HH/mm I have tried most of the codes i could find. below will help at least a little. tweak and fix :)

Below may help also

set DD=%DATE:~0,2%

set MM=%DATE:~3,2%

set YY=%DATE:~8,2%

set YYYY=%DATE:~6,4%

set hh=%hh: =0%

set mm=%TIME:~3,2%

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

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

copy \Makereport\*.CSV \Makereport\%folderdate%\

cd %folderdate%
REM -( 7zip in c:\batch)
Path = c:\batch

7z a Retail.zip *.CSV -pRetailPassword

cd..

del *.csv
Reply

#15
You'll like this, change it so that it can suit your requirements.

mkdir today
Copy Desktop\test1\*.* today
setlocal enableextensions
set name=%DATE:/=_%
Rename "today" _OlddatabaseBackup_"%name%"
Reply

#16
the expression `%date:~p,n%` returns n number of characters from position p in the date string.


if my system date string is Mon23/11/2015

the command
%date:~1,3%
returns the value
Mon

the command
%date:~10,4%
returns the value
2015


and in conjunction with the md (or mkdir) command

the command
md %date:~10,4%%date:~7,2%%date:~4,2%
makes a directory named
20151123


likewise if your date string in in the format
Monday, 23/Nov/2015

the command
md %date:~16,4%%date:~12,3%%date:~9,2%
makes a directory named
2015Nov23

If you accidentally return characters from the date string that are not allowed in folder names or use invalid values for p and n you will get an error.
Additionally if you return values that include \ this may create a folder within a folder.
Reply

#17
If you want `mm-dd-yyyy` format you can use:

mkdir %date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4%
Reply

#18
If your locale has date format "DDMMYYYY" you'll have to set it this way:

set datestr=%date:~-4,4%%date:~3,2%%date:~-10,2%
mkdir %datestr%
Reply

#19
G:

cd G:/app/

mkdir %date:~7,2%%date:~-10,2%%date:~-4,4%

cd %date:~7,2%%date:~-10,2%%date:~-4,4%

sqlplus sys/sys as sysdba @c:/new
Reply

#20
I needed both the date and time and used:

mkdir %date%-%time:~0,2%.%time:~3,2%.%time:~6,2%

Which created a folder that looked like:
`2018-10-23-17.18.34`

The time had to be concatenated because it contained `:` which is not allowed on Windows.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through