Jump to content
Sign in to follow this  
tommytx

How to convert basic text time/date to managable date/time?

Recommended Posts

tommytx

1/1/2010 14:10

Can some one steer me in the direction to convert this sort of time date into something like:

01/01/2010 14:10 so that it can be added, subtracted, and/or compared....

This is what comes out of the XL spread sheet and I assume the spread sheet could deal with it, but I think I need to format it as above to get autoit to deal with it... just a point in the right direction would be a big help.

I could use autoit to break it down like so:

1/

1/

2010

14:10

and if the length of the digit is less than 2 then add a zero on the left like 01/

and if its two digits just leave it alone.. but I am sure all your super smart folks already know of an existing script that will do if for me without me re-inventing the wheel.. Thanks!

1/1/2010 14:10

2/7/2010 14:24

12/15/2012 18:15

1/1/2012 18:15

7/23/2009 18:50

10/1/2010 19:19

Edited by tommytx

Share this post


Link to post
Share on other sites
Blue_Drache

A regular expression would be the most efficient, but I don't speak the language.

StringRegExp()

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites
Melba23

tommytx,

This is a job for StringSplit and StringFormat: ;)

$sInput = "1/1/2010 4:10"

$aSplit_1 = StringSplit($sInput, " ")
$aSplit_Day = StringSplit($aSplit_1[1], "/")
$aSplit_Time = StringSplit($aSplit_1[2], ":")

$sOutPut = StringFormat("%02i/%02i/%4i", $aSplit_Day[1], $aSplit_Day[2], $aSplit_Day[3]) & " " & StringFormat("%02i:%02i", $aSplit_Time[1], $aSplit_Time[2])

ConsoleWrite($sOutPut & @CRLF)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Malkey

Another example.

#include <Date.au3>

Local $sInput = "10/31/2012 9:5"
Local $TimeNow = _NowCalc() ; Returns the current Date and Time in format YYYY/MM/DD HH:MM:SS for use in date calculations.

Local $aOutPut = StringRegExp($sInput, "(d{1,2})/(d{1,2})/(d{1,4})h*(d{1,2}):(d{1,2}):?(d{0,2})", 3)
Local $sOutPutDate = StringFormat("%04i/%02i/%02i %02i:%02i:%02i", $aOutPut[2], $aOutPut[0], $aOutPut[1], $aOutPut[3], $aOutPut[4], $aOutPut[5])

Local $iDateCalcD = _DateDiff('D', $sOutPutDate, $TimeNow)
Local $iDateCalch = _DateDiff('h', $sOutPutDate, $TimeNow)
Local $iDateCalcm = _DateDiff('n', $sOutPutDate, $TimeNow)
Local $iDateCalcS = _DateDiff('s', $sOutPutDate, $TimeNow)

MsgBox(4096, "Time difference", StringFormat("    %19sn -  %19sn =  %i Days %2i hrs %2i min %2i sec", _
        $TimeNow, $sOutPutDate, $iDateCalcD, Int($iDateCalch - $iDateCalcD * 24), Int($iDateCalcm - $iDateCalch * 60), Int($iDateCalcS - $iDateCalcm * 60)))

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  

×