1

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    <DIR>          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    <DIR>          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 ?

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.