Format the SentOn to display only date

Viewed 499

I am trying to construct a filename from an Outlook item.

I have code to save the file with the date (from mySelectedItem.SentOn) in the filename .

I don't need hours, minutes and seconds, like "19062019 105228-from-to-subject".

Dim msgFileName As String
msgFileName = mySelectedItem.SentOn & "-" & _
              mySelectedItem.SentOnBehalfOfName & "-" & _
              mySelectedItem.To & "-" & _
              mySelectedItem.Subject

I only need "19062019-from-to-subject".

1 Answers

This will Work

All you have to use Format function on the Date. Like Format(date, "ddmmyyy")

Dim msgFileName As String
msgFileName = Format(mySelectedItem.SentOn,"ddmmyyyy") & "-" & _
              mySelectedItem.SentOnBehalfOfName & "-" & _
              mySelectedItem.To & "-" & _
              mySelectedItem.Subject
Related