Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Seems to me the first challenge is reading your custom string as a valid date. In <a href="https://stackoverflow.com/questions/7209274/mismatched-datatype-in-access-query">your previous question</a>, you gave this as a sample string stored in your [AlarmStart] field:</p> <pre><code>Tue Jan 18 10:10:57 2011 </code></pre> <p>The problem is VBA doesn't recognize that string as containing a valid Date/Time value. </p> <pre><code>? IsDate("Tue Jan 18 10:10:57 2011") False </code></pre> <p>However, if you revise that string (drop the day of the week and move year before time), you can produce a string which VBA recognizes as a valid date.</p> <pre><code>? IsDate("Jan 18 2011 10:10:57") True </code></pre> <p>So you can use a function to split apart the string, rearrange the pieces you need, and return a Date/Time value. </p> <pre><code>Public Function DateFromCustomString(ByVal pIn As String) As Variant Dim varPieces As Variant Dim strNew As String Dim varReturn As Variant varPieces = Split(pIn) strNew = Join(Array(varPieces(1), varPieces(2), varPieces(4), _ varPieces(3)), " ") If IsDate(strNew) Then varReturn = CDate(strNew) Else varReturn = Null End If DateFromCustomString = varReturn End Function </code></pre> <p>(The Split() and Join() functions are available starting with Access 2000.)</p> <p>And, once you have a Date/Time value from your string, you can use the Format() function to display it however you like.</p> <pre><code>Format(DateFromCustomString(alarmdet.AlarmStart), "ddd MMM dd yyyy hh:mm:ss") AS AlarmDateTime Format(DateFromCustomString(alarmdet.AlarmStart), "mm/dd/yyyy") AS AlarmDate </code></pre> <p>This works as described with English month name abbreviations. I don't know what will happen with Portuguese. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload