Garp99HasSpoken Posted February 24, 2013 Share Posted February 24, 2013 I need a way of getting the opposite of the function _date_time_systemtimetodatestr()which this function given yyyy/mm/dd returns "February 23, 2013" as per my PC setup.That's the date I use in ListView column. Problem is now to edit that item I need to takethat date and convert it back to yyyy/mm/dd . So I need _date_time_datestrtosystemtime()to get the opposite to use with GUICtrlCreateDate()Yes I know how to manually break apart the string and create yyyy/mm/dd but I don't wantto assume that other users will have the date format as me. I need a generic way to get the results. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 24, 2013 Moderators Share Posted February 24, 2013 Garp99HasSpoken, I suggest using Malkey's _Date_Time_Convert UDF - it converts to and from any format you care to use. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Garp99HasSpoken Posted February 25, 2013 Author Share Posted February 25, 2013 Does anyone know how to get the LOCALE_SLONGDATEFORMAT from a user's PC? From Registry or program call.There are differences between Long Date Format for English-Canada, English-United_States and English-United_KingdomI am hoping to find a method of getting the layout which the user prefers, in a format likeMMMM dd, yyyyMMMM d, yyyyMMMM-dd-yyd-MMM-yydddd, MMMM dd, yyyydddd, dd MMM, yyyydd MMMM, yyyydd MMMM yyyyd MMMM yyyyFrom there I can convert back to GUI Date/Time Picker format yyyy/mm/dd Link to comment Share on other sites More sharing options...
kylomas Posted February 25, 2013 Share Posted February 25, 2013 Garp99...,A search would have showed you that you can...Download Yashied UDF Then use function _WinAPI_GetLocaleInfo to get what you want.kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Malkey Posted February 25, 2013 Share Posted February 25, 2013 kylomasA search in the help file would show _DateTimeFormat function with the $sType parameter as "1" is that Yashied renamed in his UDF. Link to comment Share on other sites More sharing options...
Garp99HasSpoken Posted February 25, 2013 Author Share Posted February 25, 2013 @Malkey, you misunderstood my needs, as well as the same reason your date convert function would not work for my needs. @kylomas, thanks. I should indeed take a better look at what's available there. Anyways, wrote a function to handle my needs for any English or French countries, regardless of user's preference. Check out this example program. expandcollapse popup#include <Date.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> GUICreate("Date Examples", 300, 400) Global $nx=16 Global $examples[ $nx ] = [ _ "March 4, 2012", "4-March-12", "January-22-13", "14-May-12", "December 23, 2012", _ "Sunday, February 24, 2013", "Sunday, 24 February, 2013", "24 February, 2013", "29 January 2003", "4 November 2012", _ "Sunday, February 3, 2013", "Sunday, 3 February, 2013", _ "01-Jul-69", "11-Jun-14", "31-Oct-03", "3 May 11" ] $cListView = GUICtrlCreateListView("Long Date |YY/MM/DD ", 10, 10, 280, 380) For $i=0 To $nx-1 GUICtrlCreateListViewItem($examples[$i] & "|" & LongDateToString($examples[$i]), $cListView) Next _GUICtrlListView_SetColumnWidth($cListView, $i, $LVSCW_AUTOSIZE_USEHEADER) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Exit ; Convert long month string to number Func LongMonthToNum($mmmm) Local $i, $mm = 0 If (StringRight(@OSLang, 2) = "0c") Then ; French countries Local $months[12] = [ "jan", "fev", "mar", "avr", "mai", "jui", "jul", "aou", "sep", "oct", "nov", "dec" ] ; ElseIf (StringRight(@OSLang, 2) = "09") Then ; English countries Else ; Handle all others Local $months[12] = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ] EndIf For $i=0 To 11 If (StringLeft($mmmm, 3) = $months[$i]) Then $mm = $i + 1 ExitLoop EndIf Next Return $mm EndFunc ;==>LongMonthToNum ; Convert user's Long Date format to yyyy/mm/dd for GUI date/time picker Func LongDateToString($dt) Local $ymd, $lm, $yy = 0, $mm = 0, $dd = 0 ; Check for ddd, MMMM d, yyyy" If (StringRegExp($dt, "\w*, \w* \d{1,2}, \d{4}")) Then $yy = StringRegExpReplace($dt, "\w*, (\w*) (\d{1,2}), (\d{4})", "\3") $dd = StringRegExpReplace($dt, "\w*, (\w*) (\d{1,2}), (\d{4})", "\2") $lm = StringRegExpReplace($dt, "\w*, (\w*) (\d{1,2}), (\d{4})", "\1") $mm = LongMonthToNum($lm) ConsoleWrite("Case 1: " & $dt & " --> lm (" & $lm & ") " & $yy & "-" & $mm & "-" & $dd & @CRLF) ; Check for "MMMM dd, yyyy" or "MMMM d, yyyy" ElseIf (StringRegExp($dt, "\w* \d{1,2}, \d{4}")) Then $yy = StringRegExpReplace($dt, "(\w*) (\d{1,2}), (\d{4})", "\3") $dd = StringRegExpReplace($dt, "(\w*) (\d{1,2}), (\d{4})", "\2") $lm = StringRegExpReplace($dt, "(\w*) (\d{1,2}), (\d{4})", "\1") $mm = LongMonthToNum($lm) ConsoleWrite("Case 2: " & $dt & " --> lm (" & $lm & ") " & $yy & "-" & $mm & "-" & $dd & @CRLF) ; Check for "MMMM-dd-yy" ElseIf (StringRegExp($dt, "\w*-\d\d-\d\d")) Then $yy = StringRegExpReplace($dt, "(\w*)-(\d\d)-(\d\d)", "\3") $dd = StringRegExpReplace($dt, "(\w*)-(\d\d)-(\d\d)", "\2") $lm = StringRegExpReplace($dt, "(\w*)-(\d\d)-(\d\d)", "\1") $mm = LongMonthToNum($lm) ConsoleWrite("Case 3: " & $dt & " --> lm (" & $lm & ") " & $yy & "-" & $mm & "-" & $dd & @CRLF) ; Check for "dddd, dd MMMM, yyyy" ElseIf (StringRegExp($dt, "\w*, \d{1,2} \w*,? \d{4}")) Then $yy = StringRegExpReplace($dt, "\w*, (\d{1,2}) (\w*),? (\d{4})", "\3") $dd = StringRegExpReplace($dt, "\w*, (\d{1,2}) (\w*),? (\d{4})", "\1") $lm = StringRegExpReplace($dt, "\w*, (\d{1,2}) (\w*),? (\d{4})", "\2") $mm = LongMonthToNum($lm) ConsoleWrite("Case 4: " & $dt & " --> lm (" & $lm & ") " & $yy & "-" & $mm & "-" & $dd & @CRLF) ; Check for "dd MMMM, yyyy" or "d MMMM yyyy" or "dd MMMM yyyy" ElseIf (StringRegExp($dt, "\d{1,2} \w*,? \d{4}")) Then $yy = StringRegExpReplace($dt, "(\d{1,2}) (\w*),? (\d{4})", "\3") $dd = StringRegExpReplace($dt, "(\d{1,2}) (\w*),? (\d{4})", "\1") $lm = StringRegExpReplace($dt, "(\d{1,2}) (\w*),? (\d{4})", "\2") $mm = LongMonthToNum($lm) ConsoleWrite("Case 5: " & $dt & " --> lm (" & $lm & ") " & $yy & "-" & $mm & "-" & $dd & @CRLF) ; Check for "d-MMMM-yy" or "dd-MMMM-yy" ElseIf (StringRegExp($dt, "\d{1,2}-\w*-\d\d")) Then $yy = StringRegExpReplace($dt, "(\d{1,2})-(\w*)-(\d\d)", "\3") $dd = StringRegExpReplace($dt, "(\d{1,2})-(\w*)-(\d\d)", "\1") $lm = StringRegExpReplace($dt, "(\d{1,2})-(\w*)-(\d\d)", "\2") $mm = LongMonthToNum($lm) ConsoleWrite("Case 6: " & $dt & " --> lm (" & $lm & ") " & $yy & "-" & $mm & "-" & $dd & @CRLF) ; Check for d MMMM yy" or "dd MMMM yy" (mainly French countries) ElseIf (StringRegExp($dt, "\d{1,2} \w* \d\d")) Then $yy = StringRegExpReplace($dt, "(\d{1,2}) (\w*) (\d\d)", "\3") $dd = StringRegExpReplace($dt, "(\d{1,2}) (\w*) (\d\d)", "\1") $lm = StringRegExpReplace($dt, "(\d{1,2}) (\w*) (\d\d)", "\2") $mm = LongMonthToNum($lm) ConsoleWrite("Case 7 " & $dt & " --> lm (" & $lm & ") " & $yy & "-" & $mm & "-" & $dd & @CRLF) EndIf If ($yy > 33 And $yy < 100) Then $yy += 1900 If ($yy < 34) Then $yy += 2000 $ymd = StringFormat("%04d/%02d/%02d", $yy, $mm, $dd) Return $ymd EndFunc ;==>LongDateToString Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now