Jump to content

need to convert string into date


Recommended Posts

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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)

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...