Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Prompt query (Extracting Day Number, Month Number etc)

Status
Not open for further replies.

OMJ

Technical User
May 7, 2008
9
GB
Hi, I've got a command prompt batch script which extracts the day of week, day number, month number, year, hour and seconds. Unfortunately, whilst it does work, it gets the day number and month number confused when ran with US regional settings - and it needs to work in both UK and US settings. Is there any way around this so it extracts them correctly regardless? Whether this means using different code or modifying what I've got below...?

For /f "tokens=1-7 delims=.:/-, " %%i in ('echo exit^|command /K prompt $D $T ') do (
For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (
rem the following variables are populated as described below:
rem %%i = day of week
rem %%j = day number
rem %%k = month number
rem %%l = year
rem %%m = hour
rem %%n = mins
rem %%o = seconds
)
)
 
Other than changing the user's date format, I don't know of a good way. The only thing that I can think of is to change the order of the items as required by the localization settings. I believe that vb script can get the right info always, but it would take someone more skilled than I. Here are a couple of past discussions of date [and other] localization issues with using batch files to extract info.

thread779-1371429
thread779-1448543
thread779-1383551
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top