title: Trouble with date formats VBA-Excel
body: <p>I have an Excel tool, that converts the current time and date into UTC time, and then saves that time and date in a data base (which is also an Excel file). The problem is, that when someone in Mexico, for example, tries to use this tool, the format of the date is different (DD-MM-YY instead of MM-DD-YY), and it is saved incorrectly in the data base. Here is the code that converts the current time and date to UTC:</p>
  
  <pre><code>Option Explicit
  
  Public Declare Function SystemTimeToFileTime Lib _
    "kernel32" (lpSystemTime As SYSTEMTIME, _
    lpFileTime As FILETIME) As Long
  
  Public Declare Function LocalFileTimeToFileTime Lib _
    "kernel32" (lpLocalFileTime As FILETIME, _
    lpFileTime As FILETIME) As Long
  
  Public Declare Function FileTimeToSystemTime Lib _
    "kernel32" (lpFileTime As FILETIME, lpSystemTime _
    As SYSTEMTIME) As Long
  
  Public Type FILETIME
      dwLowDateTime As Long
      dwHighDateTime As Long
  End Type
  
  Public Type SYSTEMTIME
      wYear As Integer
      wMonth As Integer
      wDayOfWeek As Integer
      wDay As Integer
      wHour As Integer
      wMinute As Integer
      wSecond As Integer
      wMilliseconds As Integer
  End Type
  
  Public Function LocalTimeToUTC(dteTime As Date) As Date
  
      Dim dteLocalFileTime As FILETIME
      Dim dteFileTime As FILETIME
      Dim dteLocalSystemTime As SYSTEMTIME
      Dim dteSystemTime As SYSTEMTIME
  
      dteLocalSystemTime.wYear = CInt(Year(dteTime))
      dteLocalSystemTime.wMonth = CInt(Month(dteTime))
      dteLocalSystemTime.wDay = CInt(Day(dteTime))
      dteLocalSystemTime.wHour = CInt(Hour(dteTime))
      dteLocalSystemTime.wMinute = CInt(Minute(dteTime))
      dteLocalSystemTime.wSecond = CInt(Second(dteTime))
  
      Call SystemTimeToFileTime(dteLocalSystemTime, _
        dteLocalFileTime)
      Call LocalFileTimeToFileTime(dteLocalFileTime, _
        dteFileTime)
      Call FileTimeToSystemTime(dteFileTime, dteSystemTime)
  
      LocalTimeToUTC = CDate(dteSystemTime.wMonth &amp; "/" &amp; _
        dteSystemTime.wDay &amp; "/" &amp; _
        dteSystemTime.wYear &amp; " " &amp; _
        dteSystemTime.wHour &amp; ":" &amp; _
        dteSystemTime.wMinute &amp; ":" &amp; _
        dteSystemTime.wSecond)
  End Function
  </code></pre>
  
  <p>And then here is the formula that writes the date and time: <code>localtimetoutc(NOW())</code></p>
  
  <p>Then I just save the value of this cell into a variable in VBA (a variant variable) and then I paste the value of that variable into the data base. It works perfect for users in the US, but sometimes it fails for non-american users. How can I make sure that it won't fail? That is, how can I force VBA to use the format I need?</p>
  
  <p>Regards,</p>