Date format on the output of cmdshell dir C:\ /TC I would like to ask you guys if anyone of you had this trouble before.

In SQL I read the create time of the file like

exec master.dbo.xp_cmdshell 'dir C:\ /TC'


which gives me;

07/14/2009  04:20    &lt;DIR&gt;          Windows


As you noticed the date format of this is mm/dd/yyyy although it's set to dd/mm/yyyy format in region settings.

Same script on different PC returns

14/07/2009  04:20    &lt;DIR&gt;          Windows



Is there any setting for this you guys aware ?
And is there any method to change the format of create time of the
command ?
You can get the date format of dd/mm/yy by using wmic command. This command allows you to get current date without getting affected by regional settings.

**@echo off

    SETLOCAL EnableDelayedExpansion

    for /f "skip=1 tokens=1-6 delims= " %%a in ('wmic path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') do (
        IF NOT "%%~f"=="" (
            set /a FormattedDate=10000 * %%f + 100 * %%d + %%a
            set /a FormattedTime=%%b * 10000 + %%c * 100 + %%e
        )
    )

    for /f %%f in ("D:\Test*.zip") DO set filename=%%~nf
move "D:\Test*.zip" "D:\%FormattedDate%%FormattedTime%-%filename%.zip"**


You can save it as date.bat and run this batch file by executing the following in command prompt:

C:>date.bat