Computing.Net > Forums > Programming > get date command?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

get date command?

Reply to Message Icon

Name: Wolfrace
Date: April 28, 2005 at 01:39:25 Pacific
OS: Dos
CPU/Ram: n/a
Comment:

Hi,

I am trying to write a script/batch file which creates a folder named with the current days date... I am currently using other commands like md %username% which creates a folder after the persons username. Unfortuantely the command md %date% or get_date does not work in Dos...

Any help would be much appreciated.

Regards.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 28, 2005 at 03:00:03 Pacific
Reply:

Hi Wolf,

Yeah, there is no %date% built into DOS, so you need to get the date into a var.

You can use this batch to set DAY DATE & TIME vars:

::**
@echo off > quit.bat

if not %OS%'==Windows_NT' goto 9x

echo.|date>datevar.bat
echo.|time>timevar.bat

echo set DATEvar=%%5>the.bat
call datevar

echo set DAYvar=%%4>the.bat
call datevar

echo set TIMEvar=%%4>the.bat
call timevar

goto end

:9x

echo.|date>datevar.bat
echo.|time>timevar.bat

echo set DATEvar=%%4>current.bat
call datevar

echo set DAYvar=%%3>current.bat
call datevar

echo set TIMEvar=%%3>current.bat
call timevar

:end
::**

This sucess of this batch will depend on the version, the language and the regional / layout of the DATE & TIME.

Using a var to name a file or directory will fail if the var contains chars not allowed in file / directory names.

[/\.;; etc]

HTH

M2


If at first you don't succeed, you're about average.


0

Response Number 2
Name: ootsoo
Date: April 28, 2005 at 04:53:14 Pacific
Reply:

This porblem has a very simple solution.
Go to Control panel/Reginal settings.
go to Date tab.
change the delimiter to - instead of '/' that is set as default.
Apply the changes.
then perform "md%DATE%" which will succeed as "26-05-05" as folder name...

regards,
Ootsooboo


0

Response Number 3
Name: Mechanix2Go
Date: April 28, 2005 at 05:04:35 Pacific
Reply:

Control Panel will change the layout, but won't help DOS create the %DATE% var.

M2


If at first you don't succeed, you're about average.


0

Response Number 4
Name: Wolfrace
Date: April 28, 2005 at 05:20:58 Pacific
Reply:

Hi both,

Thanks for your help and quick responses. M2, the resolution that Ootsooboo gave does indeed work like a dream! (thanks Ootsooboo)

Thanks :-)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: get date command?

get date from CMOS in C++ www.computing.net/answers/programming/get-date-from-cmos-in-c/5922.html

get date into vars; layout independ www.computing.net/answers/programming/get-date-into-vars-layout-independ/14133.html

Getting and Setting modified date\t www.computing.net/answers/programming/getting-and-setting-modified-datet/10109.html