Search code examples
vbscriptdate-conversion

VBScript Convert value to Date


I have a VBScript that runs on the developer machine, in which the following line of code

CDate("01/09/2017")

returns the date as 1 September 2017.

But when deployed on certain clients the same line of code returns 9 January 2017 as the date.

How can I control this?


Solution

  • This has been answered before in detail;

    Use SetLocale() to choose how you want VBScript to interpret the value.

    SetLocale(1106) 'Set to United Kingdom
    WScript.Echo CDate("01/09/2017")
    

    For valid Locale ID values see Microsoft Locale ID Values (you also appear to able to use valid IETF language tag codes as well like en-us etc).