title: How to round oMail.ReceivedTime to nearest minute?
body: <p>I've a VBA macro that will save an email with the file name &quot;yymmdd.hhmm.[Sender].[Recipient].[Subject Line].txt&quot; that works almost the way I want.</p>
  <p>The issue is that the time displayed in Outlook (and the files that are saved) will round the received time to the nearest minute. Outlook will take the received time from the header, but if an email is received at 30-59 seconds past the minute, it will “round up” to the next minute. So an email received at 15:00:30 will display in Outlook (and my saved txt file) as 3:01pm.<br />
  The generated file name, however, will display the &quot;hhmm&quot; as &quot;1500&quot;</p>
  <p>This discrepancy is causing issues because it looks like times are being altered.</p>
  <p>How do I either get my macro to round to the nearest minute, or get Outlook to not round up the displayed time?</p>
  <pre class="lang-vb prettyprint-override"><code>Option Explicit
  Public Sub SaveMessageAsTxt()
   Dim oMail As Outlook.MailItem
   Dim objItem As Object
   Dim sPath As String
   Dim dtDate As Date
   Dim sName As String
   Dim enviro As String
   enviro = CStr(Environ(&quot;USERPROFILE&quot;))
   For Each objItem In ActiveExplorer.Selection
   If objItem.MessageClass = &quot;IPM.Note&quot; Then
   Set oMail = objItem
  sName = oMail.SenderName &amp; &quot;.&quot; &amp; oMail.Recipients(1) &amp; &quot;.&quot; &amp; oMail.Subject
   ReplaceCharsForFileName sName, &quot;&quot;
  dtDate = oMail.ReceivedTime
   sName = Format(dtDate, &quot;yymmdd.&quot;, vbUseSystemDayOfWeek, _
   vbUseSystem) &amp; Format(dtDate, &quot;hhnn&quot;, _
   vbUseSystemDayOfWeek, vbUseSystem) &amp; &quot;.&quot; &amp; sName &amp; &quot;.txt&quot;
  sPath = enviro &amp; &quot;\Documents\Saved Emails\&quot;
   Debug.Print sPath &amp; sName
   oMail.SaveAs sPath &amp; sName, olTXT
  End If
   Next
  End Sub
  
  
  Private Sub ReplaceCharsForFileName(sName As String, sChr As String)
   sName = Replace(sName, &quot;'&quot;, sChr)
   sName = Replace(sName, &quot;*&quot;, sChr)
   sName = Replace(sName, &quot;/&quot;, sChr)
   sName = Replace(sName, &quot;\&quot;, sChr)
   sName = Replace(sName, &quot;:&quot;, sChr)
   sName = Replace(sName, &quot;?&quot;, sChr)
   sName = Replace(sName, Chr(34), sChr)
   sName = Replace(sName, &quot;&lt;&quot;, sChr)
   sName = Replace(sName, &quot;&gt;&quot;, sChr)
   sName = Replace(sName, &quot;|&quot;, sChr)
  End Sub
  </code></pre>