Announcement

Collapse
No announcement yet.

Script to change windows date format

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to change windows date format

    hi all,

    I'm running an application that needs the Windows short date format to be "yyyy-MM-dd".
    Is there a way to create a script that will change the format and after I finish running the application to turn the date format as it was before ?

    Thanks in advance !

  • #2
    Re: Script to change windows date format

    you can use a script (kix, vbs or batch) to edit a value (per user!) in this registry key: HKEY_CURRENT_USER\Control Panel\International\

    To be able to undo the changes after the application ended, you first copy the original value of the item "sShortDate".
    Then via control panel manually change the short date notation. And copy the the new value too from the registry.
    Now you have both values that you use in the script to edit the "sShortDate" registry item.

    What script language do you prefere using for this?
    Is it one and the same script that changes the short date value, start the application and afterwards redo the short date value?

    /Rems
    Last edited by Wired; 16th July 2011, 23:13. Reason: nuked spammer mention

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Script to change windows date format

      Thanks for the answer.

      What I need is a script in which I can change the "sShortDate" from dd/MM/yyyy to MM/dd/yyyy for example. Also it would be nice if possible to edit the code in order to chenge the "sShortDate.
      I don't know any scripting so anything that works it's ok.

      Comment


      • #4
        Re: Script to change windows date format

        Originally posted by kogar View Post
        Thanks for the answer.

        What I need is a script in which I can change the "sShortDate" from dd/MM/yyyy to MM/dd/yyyy for example. Also it would be nice if possible to edit the code in order to chenge the "sShortDate.
        I don't know any scripting so anything that works it's ok.
        The script below should have a vbs file extension.

        Code:
        Dim shortDate1
        Dim shortDate2
        
        ' toggle between
        shortDate1 = "yyyy-MM-dd"  '(the format required for the app)
        shortDate2 = "dd/MM/yyyy"  '(the default format for your country)
        
        '# If shortDate1 is not equal to the present format
        '#  then, set shortDate1 as the actual notation.
        '# Else, set shortDate2 as the actual notation.
        
        Dim WshShell, Re
        Set WshShell = WScript.CreateObject("WScript.Shell")
        Set re = New RegExp
        
        ToggleShortDateFormat
        
        rem -> launch app
        rem -> wait until the app is closed (http://forums.petri.com/showthread.php?p=242229#post242229)... 
        
        ' ToggleShortDateFormat
        
        Wscript.quit
        
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Sub ToggleShortDateFormat
           Dim ShortDate, Sep, Def, sKey
           Dim sShortDate, sDate, iDate
           Dim msg
        
           sKey = "HKCU\Control Panel\International\"
           sShortDate = Trim(WshShell.RegRead(sKey & "sShortDate"))
           sDate = Trim(WshShell.RegRead(sKey & "sDate"))
           iDate = Trim(WshShell.RegRead(sKey & "iDate"))
        
           ' ShortDate1 = replace(shortDate1, " ", "")
           ' ShortDate2 = replace(shortDate2, " ", "")
        
           If ShortDate1 <> sShortDate Then
             ShortDate = ShortDate1
           Else
             ShortDate = ShortDate2
           End IF
        
           Sep = DateSeperator(ShortDate)
           If Sep <> sDate Then
             WshShell.RegWrite sKey & "sDate", Sep, "REG_SZ"
             msg = vbNewline _
               & "- the Date seperator (value of 'sDate') has been edited."
           End IF
        
           Def = DisplayFormat(ShortDate)
           If Def <> iDate Then
             WshShell.RegWrite sKey & "iDate", Def, "REG_SZ"
             msg = msg  & vbNewLine _
               & "- the default format for displaying short dates " _
               & "(value of 'iDate') has been edited."
           End If
        
           WshShell.RegWrite sKey & "sShortDate", ShortDate, "REG_SZ"
           wscript.sleep 100
        
           If Len(msg) > 0 then msg = vbNewLine & vbNewLine _
               & "note," & vbNewline & "Consequently;" & msg  
        
           WshShell.popup "The format used to display dates in short date " _
             & "numeric format (value of 'sShortDate') has been changed" _
             & vbNewline _
             & vbTab & "from" & vbTab & sShortDate & vbNewline _
             & vbTab & "to  " & vbTab & ShortDate  & vbNewline _
             & vbNewline & "Now displayed as: " & FormatDateTime(date,2) _
             & msg, 3, "Information", 0+64+4096
        End Sub
        
        Function DateSeperator(dateformat)
           Dim matches
           re.Pattern = "\W"
           Set matches = re.Execute(dateformat)
        
           If matches.Count > 0 Then
             DateSeperator = matches(0).Value
           Else
             DateSeperator = " "
             wscript.echo "unable to proceed!!!"
             wscript.quit
           End If
        End Function
        
        Function DisplayFormat(dateformat)
           Select Case TRUE
             Case InStr(1,dateformat,"m",1)=1
               DisplayFormat = "0"
             Case InStr(1,dateformat,"d",1)=1
               DisplayFormat = "1"
             Case InStr(1,dateformat,"y",1)=1
               DisplayFormat = "2"
           End Select
        End Function
        /Rems
        Last edited by Rems; 28th July 2011, 21:02. Reason: swapped values of shortDate1 and 2

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Script to change windows date format

          Working !
          Thank you very much !

          /closed.

          Comment

          Working...
          X