vick

need to convert string into date

6 posts in this topic

#1 ·  Posted

HI, 

i have string like " Jun 13, 2017 14:11" format and i need to convert ind ate format so i can filter last 30 days etc.

how i can achieve it? pl  

Share this post


Link to post
Share on other sites



#2 ·  Posted

vick,

My Date_Time_Convert UDF (look in my sig below for the link) will convert that string to any date format you require.

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

#3 ·  Posted

Hi M23, 

thanks for quick reply.

i tried your UDF below way but not worked.

$sIn_Date = "Aug 01, 2013 6:30"
$sOut_Date = _Date_Time_Convert($sIn_Date, "MMM dd, yyyy hh:mm", "mm/dd/yy")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)
 

can you tell me where i am wrong pls?

Share this post


Link to post
Share on other sites

#4 ·  Posted

vick,

Looking at the code you posted, I see that the UDF returns @error 1 and @extended 8, which the UDF header tells me is "Only 12 hr hour format and no AM/PM set". So you need to define the time more closely - like this:

#include "DTC.au3"
#include <MsgBoxConstants.au3>

$sIn_Date = "Aug 01, 2013 06:30"
$sOut_Date = _Date_Time_Convert($sIn_Date, "MMM dd, yyyy HH:mm", "MM/dd/yy")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)

Note you also need to correctly code the required output string: "mm" gives you minutes, not months.

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

#5 ·  Posted

Melba's solution is the best, but if you get the string in 6:30 format instead of the 06:30 correct one, you might try this workaround

Local $aMon_Short_In[13] = [12, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
Local $sIn_Date = "Aug 01, 2013 6:30"
$tmp = $sIn_Date 
For $i = 1 to $aMon_Short_In[0]
   $tmp = StringReplace($tmp, $aMon_Short_In[$i], StringFormat("%02i", $i) )
Next
$sOut_Date = StringRegExpReplace($tmp, '(\d\d)\h(\d\d),\h(\d{4}).*', "$1/$2/$3")
MsgBox(0, "", $sIn_Date & @CRLF & $sOut_Date)

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

Hello Melba,

thanks for your help!

it works now .

 

 

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