Jump to content

Recommended Posts

Posted (edited)

I need help turning this string "20180913221626" into a formatted time string.

I need to go from this: 20180913221626

to this: 09/13/2018 10:16 PM

I do not always know what the date will be so I can not just use a variable I need to actually convert/format. 

I did see an older post in the forms that was basically the same question only the other guy did not post the working code and I can not figure out how to use _AD_GetObjectProperties properly to get what I want. 

As always any help would be appreciated. 

Here is the code I use to find the date, but it always gives me the unformatted version. 

;retrieve the items object
$oItem = $oOutlook.Session.GetItemFromID($aItems[1][0], Default)
$oItem.GetInspector

$eSentOn        = $oItem.SentOn                                         ; When was the email sent?
MsgBox("", "Sent On of the email", $eSentOn)

;*******************************************************************************
; Formats the date and time from the email
;*******************************************************************************
;Local $fDatenTime = _DateTimeFormat($eSentOn, 1)
;MsgBox("", "Formatted email time", $fDatenTime)

 $aProperties = _AD_GetObjectProperties($eSentOn)
_ArrayDisplay($aProperties, "Did the conversion work?")

 

Edited by nooneclose
Posted
#include<date.au3>

$str = "20180913221626"

msgbox(0, '' , _DateTimeFormat(stringleft($str , 4) & "/" & stringmid($str , 5 , 2) & "/" & stringmid($str , 7 ,  2) & " " & stringmid($str , 9 ,2) & ":" & stringmid($str , 11 ,2) & ":" & stringmid($str , 13) , 0))

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted

Use this UDF, and this format for the conversion, should work.

#include <MsgBoxConstants.au3>

#include "DTC.au3"

Global $sIn_Date, $sOut_Date

; Basic format
$sIn_Date =  "20180913221626"
$sOut_Date = _Date_Time_Convert($sIn_Date, "yyyyMMddHHmm", "MM/dd/yyyy at h:mm TT") ; <<<<<<<<<<<<<
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

Thank you both very much for the timely responses. Here is the code I used and it worked like a charm thank you very much! @BrewManNH and @iamtheky 

;*******************************************************************************
; Formats the date and time from the email
;*******************************************************************************
$fDateNTime = _Date_Time_Convert($eSentOn, "yyyyMMddHHmm", "MM/dd/yyyy at h:mm TT")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $eSentOn & @CRLF & $fDateNTime)

 

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
×
×
  • Create New...