Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Date format DDMMYY

Posted on 2010-09-06
10
Medium Priority
?
2,437 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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 59

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 59

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 59

Expert Comment

by:Bill Prew
ID: 33616653
Thanks.

~bp
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

971 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