Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Date format DDMMYY

Posted on 2010-09-06
10
Medium Priority
?
2,315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 400 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 57

Assisted Solution

by:Bill Prew
Bill Prew earned 600 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 96

Accepted Solution

by:
Lee W, MVP earned 1000 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 57

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 57

Expert Comment

by:Bill Prew
ID: 33616653
Thanks.

~bp
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

705 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