?
Solved

MS-DOS Date format on different computers

Posted on 2011-10-05
12
Medium Priority
?
960 Views
Last Modified: 2012-05-12
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..
 
0
Comment
Question by:at999
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 36920185
The date format may change based on regional settings, but I would expect it to be the same on every machine otherwise.
0
 
LVL 4

Assisted Solution

by:vvk
vvk earned 200 total points
ID: 36920202
date format depend on system locale settings, e.g. Control Panel -> Region and Language  so i could be different
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 36920236
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 36920239
Sorry...ignore that^
0
 

Author Comment

by:at999
ID: 36920363
vvk/paulmacd,
so what should i do to get MMDDYYYY format of current date in DOS ?

thanks
0
 
LVL 34

Assisted Solution

by:Paul MacDonald
Paul MacDonald earned 200 total points
ID: 36920412
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
 

Author Comment

by:at999
ID: 36924418
Will the date format change say if we move from windows server 2003 to windows server 2008? my machine is in US...
0
 

Author Comment

by:at999
ID: 36924590
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
 
LVL 71

Accepted Solution

by:
Qlemo earned 1600 total points
ID: 36930555
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
 

Author Comment

by:at999
ID: 36957091
how do I call VBS in an MS-DOS batch file? and get that date? thanks a lot
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 36957343
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
 

Author Comment

by:at999
ID: 36957452
thanks a lot that solved my problem...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Migration of Exchange mailbox can be done with the ExProfre.exe tool. But at times, when the ExProfre.exe tool migrates the Exchange Server user profile, it results in numerous synchronization problems. Synchronization error messages appear in the e…
Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question