Solved

Date format DDMMYY

Posted on 2010-09-06
10
1,824 Views
Last Modified: 2012-08-13
Hello

I need some DOS code to get the following date format DDMMYY, can anyone provide?

Thanks!
0
Comment
Question by:SickBoy23
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 18

Expert Comment

by:x-men
ID: 33612426
c:\>date /t

returns the date, the format is set on regional settings under short date format...

I'm not sure about the intent of the question, can you clarify?
0
 

Author Comment

by:SickBoy23
ID: 33612460
date /t provides in format 06/09/2010, I need in format 060910.  I intend to use this for scripting purposes however need in format DDMMYY

Thanks!
0
 
LVL 18

Expert Comment

by:x-men
ID: 33612587
something like this?
set z=06/09/2010
for /f "tokens=1,2,3 delims=/" %i in ('echo %z%') do echo %i%j%k

Open in new window

0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 100 total points
ID: 33612628
This is another way if you look at my article here that works independent of date format on the pc:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_1153-Using-dates-in-batch-files-scripts.html
Ask if you need more help customising.

Steve
0
 
LVL 53

Assisted Solution

by:Bill Prew
Bill Prew earned 150 total points
ID: 33612772
If you are okay assuming the date format on that maching is mm/dd/yyyy then you could just do:

set MyDate=%DATE:~-10,2%%DATE:~-7,2%%DATE:~-4,2%

~bp
0
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 250 total points
ID: 33613521
Expanding on Billprew's comment, Windows puts the current date (and the current time) into variables - %date% and %time%.

You can use these variables, but they tend to change with regional settings.  Run "ECHO %DATE%" to see how %date% is stored and then you can pull out only the aspects of the variable you want - for example, for me, I get the following when I run echo %date% (the numbers beneath in the code section illustrate the line positions)

So if I want the Month, I want to start at the 4th character and take two characters:
Month=%Date:~4,2%
The Day starts are character 7 and requires 2 digits
Day=%Date:~7,2%
And the two digit year is the last two characters - the "-" meaning starting from the reverse end of the string take everything else
Year=%Date:~-2%
And the four digit year is the last four characters
Year=%Date:~-4%

Hopefully, you can use the above and below to learn how to retrieve portions of the variable and that should answer your question. I will add that using the For... date/t method as described above is potentially better in scripts that need to be used by others in other regions.  Once you hard code DATE:~ lines, you expect the region never to change - you could do some if statements to determine the region, but then you're making things more complicated.

Mon 09/06/2010 [produced from an "ECHO %DATE%"]
00000000001111
01234567890123

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33613827
To add to that slightly even on the same machine if you have a scipt running nicely then decide to schedule it as an admin user etc. then it may well have a different profile with default date/time formats.  It might not catch you out until you realise that it uses " 1/ 1/2010" instead of "01/01/2010" or " 1- 1-2010" etc. so justbe careful!

Steve
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 33614724
Here's a routine you could use, that sets variables m, mm, d, dd, yy, yyyy which can be referenced in the script as shown in the sample echo.  Hope this helps.

~bp
@echo off
call :GetDate
echo %m%/%d%/%yy%
echo %mm%/%dd%/%yyyy%
exit /b
 
:GetDate
  REM Get date format settings from registry
  for /F "tokens=3" %%A in ('reg query "HKCU\Control Panel\International" /v iDate 2^>NUL') do set "iDate=%%A"
  for /F "tokens=3" %%A in ('reg query "HKCU\Control Panel\International" /v sDate 2^>NUL') do set "sDate=%%A"
 
  REM Get the current system date (ignore day name if present)
  for %%A in (%Date%) do set "Today=%%A"
 
  REM Parse current date based on delimiter from registry, and assign to desired user variable
  for /F "tokens=1-3 delims=%sDate%" %%A in ("%Today%") do (
    if "%iDate%"=="0" set /a "d=1%%B-100" & set /a "m=1%%A-100" & set "yyyy=%%C"
    if "%iDate%"=="1" set /a "d=1%%A-100" & set /a "m=1%%B-100" & set "yyyy=%%C"
    if "%iDate%"=="2" set /a "d=1%%C-100" & set /a "m=1%%B-100" & set "yyyy=%%A"
  )
  set "mm=%m%"
  set "dd=%d%"
  set "yy=%yyyy:~-2%"
  if %m% LSS 10 set "mm=0%m%"
  if %d% LSS 10 set "dd=0%d%"
  exit /b
)

Open in new window

0
 

Author Closing Comment

by:SickBoy23
ID: 33615557
Thanks Lee your explanation provides a great understanding which will allow me to manipulate the dates in any format I wish thanks!

Cherrs Bill and the rest of the guys. Points awarded hopefully fairly.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 33616653
Thanks.

~bp
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

778 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