MS-DOS Date format on different computers

When i do this on my computer
echo %date%
it shows
Wed 10/05/2011

I am trying to extract month/date/year from that date

Now, i am tryign to run batch program and I want to extract date in form of MMDDYYYY from that date value.

So I do this -
set DATALOADDATE=%date:~4,2%%date:~7,2%%date:~10,4%

My question is will the format of date change on other machine, is the date format - Wed 10/05/2011 dependent on the Operating system or the way user has set to? Or it will be like this on all the machines?

thanks a lot..
 
at999Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul MacDonaldDirector, Information SystemsCommented:
The date format may change based on regional settings, but I would expect it to be the same on every machine otherwise.
0
vvkCommented:
date format depend on system locale settings, e.g. Control Panel -> Region and Language  so i could be different
0
Paul MacDonaldDirector, Information SystemsCommented:
In the Solution for your web site you should be able to right-click on the project and Add Service Reference.  This should give you access to the events exposed by the service.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Paul MacDonaldDirector, Information SystemsCommented:
Sorry...ignore that^
0
at999Author Commented:
vvk/paulmacd,
so what should i do to get MMDDYYYY format of current date in DOS ?

thanks
0
Paul MacDonaldDirector, Information SystemsCommented:
I think you're doing it right, but that the source format may change if the computer is in Europe (or some such).  Without tapping in to the OS with a scripting language, there's probably not much more you can do.  This may be worth looking at though:  http://www.tech-recipes.com/rx/956/windows-batch-file-bat-to-get-current-date-in-mmddyyyy-format/
0
at999Author Commented:
Will the date format change say if we move from windows server 2003 to windows server 2008? my machine is in US...
0
at999Author Commented:
also, i tried the sample in that link -  http://www.tech-recipes.com/rx/956/windows-batch-file-bat-to-get-current-date-in-mmddyyyy-format/

but it did not work .... it gave date value - %mm%%dd%%yyyy% and not  10062011
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
That example is clumsy method of getting the date. The best way to get the date, without using VBS, is indeed just using %date%, and extract strings in relation to the end of the date string:
   echo %date:~-10,2%%date:~7,2%%date:~-4%
That way the date string works with or without weekday (which can be different between OS and machines, though in the same timezone).

However, mmddyyyy is a very, ehm, impractical format. You don't want to use yyyymmdd, if you are at formatting the date already?

The most reliable way to get the date in a defined format in a batch file is by using VBS:
@echo off
>%temp%\getdate.vbs echo wscript.echo right(100+month(date()),2) ^& right(100+day(date()),2)  ^& year(date()) 
for /F "tokens=*" %%D in ('cscript //nologo %temp%\getdate.vbs') do set DATALOADDATE=%%D
del %temp%\getdate.vbs 2>nul

Open in new window

This is particular handy if you need arithmetics, like the previous day, or 30 days ago, as that is easy to do in VBS, but a pain in cmd.exe.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
at999Author Commented:
how do I call VBS in an MS-DOS batch file? and get that date? thanks a lot
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I've showed you that - my code snippet uses that technique. It echoes commands to a .VBS file, runs that file with cscript (the console version of Windows Scripting Host), and processes the output. The .VBS file is then deleted.
0
at999Author Commented:
thanks a lot that solved my problem...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows XP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.