Jump to content
Sign in to follow this  

Outlook Format Date & Time

Recommended Posts


OS: Win XP SP 3 with Outlook 2003 SP 3

I'm trying to format the date and time that is retrieved from Outlook. The Outlook UDF had questions related to formating the date and time but I did not find a solution. In the help file I found the _DateTimeFormat function but it does not work because my result is blank. If I use $message.ReceivedTime then I get 20090107164913. How can I format this date and time to "m-d-yyyy hh:mm AMPM"?

#include <Date.au3>

$ol = ObjCreate ("Outlook.Application")
$ns = $ol.GetNameSpace("MAPI")
$AIItems = $ns.Folders("Account_Name").Folders.item("Sub_Folder_Name").Items

while 1
    ; go through them in reverse order - required if you delete anything
    for $position = $AIItems.Count to 1 step -1 

        $message = $AIItems.Item($position)
        if stringinstr($message.Categories,"AutoItFlag") then
            $message.Categories = ""
            $mRT = $message.ReceivedTime            
;~             msgbox(0,$message.Subject,$message.Body &_DateTimeFormat($mRT,0))
            msgbox(0,"Date Display Numbers Only",$mRT) ; Formated like: 20090107164913
            msgbox(0,"Tried this no date displayed",_DateTimeFormat($mRT,0))


Thank you for your help,


Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Share this post

Link to post
Share on other sites

This will convert to MM-dd-yyyy hh:mm:

$NewTime = StringRegExpReplace("20090107164913","(\d{4})(\d{2})(\d{2})(\d{2})\d{2}","$2-$3-$1 $4:$5")

You could use this pattern with a StringRegExp to get an array and then add that together to a string. (because autoit will recognise the variables as numbers it will remove the 0's in month and day),

but I think someone will be able to give an improved pattern for StringRegExpReplace which would me a much cleaner solution.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...