Jump to content
Sign in to follow this  

[SOLVED] Convert unformulated time String to a formatted string

Recommended Posts

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)

$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

Share this post

Link to post
Share on other sites

$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))


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

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

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)


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.

  • Similar Content

    • By Jahar
      Hi All,
      Please help me on how to fetch date/time of last windows 10 system restore point using autoit? Basically its about querying the last restore point.
    • By TheDcoder
      Hi everyone,
      I am bit stumped as to why I am not able to set the time in the Date control
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm:ss" GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ; Set time Local $iRet = GUICtrlSetData($idDate, '13:33:37') ConsoleWrite('GUICtrlSetData returned ' & ($iRet = 1 ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example The documentation for GUICtrlSetData clearly mentions that it uses the same format as GUICtrlRead:
      But I get failure
      What gives?
      Thanks for the help in advance!
    • By cruisepandey
      I have a string like this : 
      Global $Msga = "urrent directory is /send.  (Submission of file with log number 29381077284 is confirmed)";
      I want to extract the number 29381077284  from the string. I did StringSplit to split based on "(" and then use space to reach there, But it's not a good choice. 
      Can anyone help me with regular expression to find the number from String using AutoIT. TIA
    • By DannyJ
      I have this example string:
      2020-06-08 09:23:33 : abcdefghifjklm How to trim just the right part? Or how to trim this text right to left?
      I want to trim this string right to left until ' : '.
      In ohter words: I need the 'abcdefghifklm' text.
      I have tried StringTrimRight, but that requires 
      The number of characters to trim. Unfortunately StringSplit trims the left part of the strings.
    • By careca
      This is my take on string triggers, triggers on specific strings.
      Able to simple text pasting,
      opening links (as long as there's a www. http:\\ or https:\\ at the beggining)
      and is able to open applications, if there is a parameter in the parameter field, it uses it.
      Shows your external, lan, and gateway ip's.
      Able to change system volume by a set percentage, reading from the inputbox the number the user sets, if 0 or empty uses system default.
      I made this because the existing string trigger applications didn't do it for me.
      I did this for me, but if someone finds it useful, all the better.
  • Create New...