Make a folder named Date-Time

Aug 9, 2009
293
1
: -----Original Message-----
:
: How can I set up an alias (?) so that I can use it in a batch file to create a folder
with the current date
: and time?


Md "%@date[%_date %_time]
Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

Those will all work alias name MDT what ever you want to call it

Since the folder will be created with the same info why would you want to double up on it.
?
 
May 20, 2008
12,167
133
Syracuse, NY, USA
On Sun, 30 Oct 2011 17:15:30 -0400, Kachupp <> wrote:

|: -----Original Message-----
|:
|: How can I set up an alias (?) so that I can use it in a batch file to create a folder
|with the current date
|: and time?
|
|
|Md "%@date[%_date %_time]
|Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
|
|Those will all work alias name MDT what ever you want to call it

Also, if you don't mind the DATETIME format,

alias datedir `*md %_datetime`
 
Jul 12, 2008
287
0
Las Vegas, NV
When I ran

alias dd3 Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

or

alias dd2 Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"


it changed the alias to equal the folder name. So, the first time I ran it, it made

11-01-11 22.43.19

But then, dd3 turned into '11-01-11 22.43.19' so it couldn't create the folder as one with that name already existed.

Huh? Am I doing something wrong here?

Chuck
 
Aug 9, 2009
293
1
: -----Original Message-----
: Subject: RE: [Support-t-3331] Re: Make a folder named Date-Time
:
: When I ran
:
: alias dd3 Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
:
: or
:
: alias dd2 Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
:
:
: it changed the alias to equal the folder name. So, the first time I ran it, it made
:
: 11-01-11 22.43.19
:
: But then, dd3 turned into '11-01-11 22.43.19' so it couldn't create the folder as one
with that name
: already existed.
:
: Huh? Am I doing something wrong here?
:
: Chuck

Timing. You will need a delay between issuing the aliases 2 seconds should be ample.
 
Jul 12, 2008
287
0
Las Vegas, NV
Of these two, the first still gave me errors (10 second pause), but the second one worked fine.

dd2=Md "%@date[%_date %_time]
dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

Thanks,
Charles
 
May 20, 2008
3,515
4
Elkridge, MD, USA
From: CWBillow
| Of these two, the first still gave me errors (10 second pause), but
| the second one worked fine.
|
| dd2=Md "%@date[%_date %_time]
| dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

From the format, I presume you do this in an alias definition file. Did you look at _isodate?
One more comment. The method of obtaining the date and time in separate calls to the OS has bit me in the past - if you happen to do it within a few milliseconds before midnight, the date and time returned could be from different days, resulting in a combination nearly 24 hours obsolete... Two methods available to fix this, one a lot more elaborate than would suit an alias: get date, get time, get date again - if dates mismatch, get time again. The other is to use the single call made obtaining _DATETIME, and editing its value into the format you want, along the lines (NOT TESTED!!!):

alias dd=`SET z=%_datetime %+ MD "%@instr[0,4,%z]-%@instr[4,2,%z]-%@instr[6,2,%z] %@instr[8,2,%z].%@instr[10,2,%z].%@instr[12,2,%z]"`

BTW, you can force _date and _time to return data in the format you want by setting the registry format for short date and time, either temporarily (for the execution of the MD command), or permanently.
--
HTH, Steve
 
Aug 9, 2009
293
1
Ooppps not surprised the first one gives an error ... the _time variable does not belong
there sorry! Chuck
Time is ignored! In dd2

: -----Original Message-----
: Subject: RE: [Support-t-3331] Re: Make a folder named Date-Time
:
: Of these two, the first still gave me errors (10 second pause), but the second one
worked fine.
:
: dd2=Md "%@date[%_date %_time]
: dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
:
: Thanks,
: Charles
 

samintz

Scott Mintz
May 20, 2008
1,555
26
Solon, OH, USA
I don't know if any of your issues are related to not having backquotes
around your alias definition.

For example, these two definitions will yield different results:

alias mdd1=`Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"`
alias mdd2=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

alias
mdd1=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
mdd2=Md "11-02-11 10.53.51"

-Scott




Ooppps not surprised the first one gives an error ... the _time variable
does not belong
there sorry! Chuck
Time is ignored! In dd2

: -----Original Message-----
: Subject: RE: [Support-t-3331] Re: Make a folder named Date-Time
:
: Of these two, the first still gave me errors (10 second pause), but the
second one
worked fine.
:
: dd2=Md "%@date[%_date %_time]
: dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
:
: Thanks,
: Charles
 
Jul 12, 2008
287
0
Las Vegas, NV
Cool! I'll give the [untested] alias a look.

Thanks,
Chuck

From: CWBillow
| Of these two, the first still gave me errors (10 second pause), but
| the second one worked fine.
|
| dd2=Md "%@date[%_date %_time]
| dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

From the format, I presume you do this in an alias definition file. Did you look at _isodate?
One more comment. The method of obtaining the date and time in separate calls to the OS has bit me in the past - if you happen to do it within a few milliseconds before midnight, the date and time returned could be from different days, resulting in a combination nearly 24 hours obsolete... Two methods available to fix this, one a lot more elaborate than would suit an alias: get date, get time, get date again - if dates mismatch, get time again. The other is to use the single call made obtaining _DATETIME, and editing its value into the format you want, along the lines (NOT TESTED!!!):

alias dd=`SET z=%_datetime %+ MD "%@instr[0,4,%z]-%@instr[4,2,%z]-%@instr[6,2,%z] %@instr[8,2,%z].%@instr[10,2,%z].%@instr[12,2,%z]"`

BTW, you can force _date and _time to return data in the format you want by setting the registry format for short date and time, either temporarily (for the execution of the MD command), or permanently.
--
HTH, Steve
 
Jul 12, 2008
287
0
Las Vegas, NV
Got it.

Thanks,
Chuck

Ooppps not surprised the first one gives an error ... the _time variable does not belong
there sorry! Chuck
Time is ignored! In dd2

: -----Original Message-----
: Subject: RE: [Support-t-3331] Re: Make a folder named Date-Time
:
: Of these two, the first still gave me errors (10 second pause), but the second one
worked fine.
:
: dd2=Md "%@date[%_date %_time]
: dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
:
: Thanks,
: Charles
 
Jul 12, 2008
287
0
Las Vegas, NV
I'll try them, thanks.

Chuck



I don't know if any of your issues are related to not having backquotes
around your alias definition.

For example, these two definitions will yield different results:

alias mdd1=`Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"`
alias mdd2=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

alias
mdd1=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
mdd2=Md "11-02-11 10.53.51"

-Scott




Ooppps not surprised the first one gives an error ... the _time variable
does not belong
there sorry! Chuck
Time is ignored! In dd2

: -----Original Message-----
: Subject: RE: [Support-t-3331] Re: Make a folder named Date-Time
:
: Of these two, the first still gave me errors (10 second pause), but the
second one
worked fine.
:
: dd2=Md "%@date[%_date %_time]
: dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
:
: Thanks,
: Charles
 
Sep 19, 2011
1
0
I've been working on this, but don't have time right now to figure out what's wrong with mine... :(
Simply: I need to create a "YYYY-MM-DD HH-MM" foldername from an automated batch file, and Subst Z: for it.
The above looks almost right to me, but I'm getting folders named _date _time] and similar.
Any quick fixes? Thx...
 

samintz

Scott Mintz
May 20, 2008
1,555
26
Solon, OH, USA
Actually, use %_isodate instead of %_date and %_hour and %_minute for the time.

set foldername="%_isodate %_hour-%@right[2,0%_minute]"
subst /d Z: > nul
subst Z: %foldername
 
May 20, 2008
3,515
4
Elkridge, MD, USA
I only reference _date/_isodate, _hour, and _minute individually to obtain the current date and time if I can guarantee that midnight cannot occur between the first and last reference. Otherwise I always use a single access to the system clock, usually via _datetime, and if I need the individual elements I use @instr[] on the string returned:

set now=%_datetime
set foldername="%@instr[2,2,%now]-%@instr[2,2,%now]-%@instr[4,2,%now] %@instr[6,2,%now]-%@instr[8,2,%now]"

to generate a name in which the date (using 2-digit year) and time (using hyphen between hours and minutes, no seconds) are separated by a single space. For my own use, I typically use NO separators, which makes it much simpler; to avoid very large directories (e.g. the parent directory of all these folders) I typically break it into a hierarchy - for frequent items (e.g., pictures of events) I make year+month one level, and day+time a lower level. For less frequent items (e.g., monthly bills) year is the higher level.
--
HTH, Steve
 
Aug 2, 2011
258
4
Berlin, Germany
I only reference _date/_isodate, _hour, and _minute individually to obtain the current date and time if I can guarantee that midnight cannot occur between the first and last reference. Otherwise I always use a single access to the system clock, usually via _datetime, and if I need the individual elements I use @instr[] on the string returned:

set now=%_datetime
set foldername="%@instr[2,2,%now]-%@instr[2,2,%now]-%@instr[4,2,%now] %@instr[6,2,%now]-%@instr[8,2,%now]"

to generate a name in which the date (using 2-digit year) and time (using hyphen between hours and minutes, no seconds) are separated by a single space. For my own use, I typically use NO separators, which makes it much simpler; to avoid very large directories (e.g. the parent directory of all these folders) I typically break it into a hierarchy - for frequent items (e.g., pictures of events) I make year+month one level, and day+time a lower level. For less frequent items (e.g., monthly bills) year is the higher level.
--
HTH, Steve
Hello Steve,

that's exactly the way I like (and do) it too.
 

Similar threads