Jump to content
Sign in to follow this  
Melba23

Date_Time_Convert - BugFix version 27 May 15

Recommended Posts

Thomymaster,

No - as I do not see this as of general use.. I suggest using StringRight to get the ms digits, StringTrimRight to remove them before conversion, and then concatenate the converted DTG with the stripped ms value. Or given the simplicity of the conversion just use a simple RegEx:

$sInput = "07/06/2015 15:02:04.234"

$sOutput = StringRegExpReplace($sInput, "^(\d\d)\/(\d\d)\/(.*)$", "$2.$1.$3")

ConsoleWrite($sOutput & " - Returned" & @CRLF & "06.07.2015 15:02:04.234 - Required" & @CRLF)

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

 

Share this post


Link to post
Share on other sites

not sure what's going on... this isn't working (using autoit v3.3.12)

but if i take out the "hh:mm" it works

#include <DTC.au3>
$date = "2015:11:16 10:14"

$month_short = _Date_Time_Convert($date, "yyyy:MM:dd hh:mm", "MM")
$month_long = _Date_Time_Convert($date, "yyyy:MM:dd hh:mm", "MMMM")
$year = _Date_Time_Convert($date, "yyyy:MM:dd hh:mm", "yyyy")
Debug($date, $month_short, $month_long, $year)

any ideas?

Share this post


Link to post
Share on other sites

gcue,

If you look at the @error/@extended values being returned and check the function header you will see that you have told the UDF that the hours are in 12-hour format but you have not specified AM/PM. If you change the hour format to 24-hour or specify AM/PM it works:

#include <DTC.au3>

$date = "2015:11:16 10:14"
; Use 24-hour format
$month_short = _Date_Time_Convert($date, "yyyy:MM:dd HH:mm", "MM")
$month_long = _Date_Time_Convert($date, "yyyy:MM:dd HH:mm", "MMMM")
$year = _Date_Time_Convert($date, "yyyy:MM:dd HH:mm", "yyyy")
ConsoleWrite($month_short & " - " & $month_long & " - " & $year & @CRLF)

$date = "2015:11:16 10:14 A"
; Specify AM/PM
$month_short = _Date_Time_Convert($date, "yyyy:MM:dd hh:mm T", "MM")
$month_long = _Date_Time_Convert($date, "yyyy:MM:dd hh:mm T", "MMMM")
$year = _Date_Time_Convert($date, "yyyy:MM:dd hh:mm T", "yyyy")
ConsoleWrite($month_short & " - " & $month_long & " - " & $year & @CRLF)

At times I wonder why I bother adding all the error messages and writing function headers......

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

 

Share this post


Link to post
Share on other sites

ah sorry about that.. i will take head next time =)

thank you for your help!

Share this post


Link to post
Share on other sites

@Melba23Awesome, tried for 45 min to convert a string based on the $LOCALE_SSHORTDATE.

Found a different thread with your remark "My Date_Time_Convert UDF (look in my sig below for the link) will convert that string to any date format you require."

- bam - 1 minute later done. Thank you very much.

Share this post


Link to post
Share on other sites

Hi @Melba23 ,

I was having some issues with automation of Logs wherein the Date Time is either in English or in some Locale based on the configured OS. It would be great if we come to know about the Locale and then the array of Month Abbreviation in the chosen language is  used/created. Would this be possible ?

I have been trying to find some list or anything that would help me in getting the Abbreviations but have hit the wall.

 

Local $German = '25 Mrz 2018'
Local $English = '25 Mar 2018'
ConsoleWrite(_Date_Time_Convert($German,'dd MMM yyyy','dd/MM/yyyy') & @CRLF) ;<-- Returns Empty
ConsoleWrite(_Date_Time_Convert($English,'dd MMM yyyy','dd/MM/yyyy') & @CRLF)

Regards

DR.

Edited by DeltaRocked
typo

Share this post


Link to post
Share on other sites

DeltaRocked,

This script will get you the short month names for the currently set locale in the OS.

This code seems to do it for all locales, but I am not sufficiently C literate to convert it.

M23

Edit: Just found this script - looking into it now.

Edit 2: Here you go:

#include <WinAPILocale.au3>
#include <Array.au3>

Global $aLocales[10] = [0]
For $i = 0 To 0xFFFF
    ; Check if valid LCID
    $iLocale = _WinAPI_GetLocaleInfo($i, 0x01)
    If $iLocale Then
        ; Store LCID
        $aLocales[0] += 1
        ; Resize array as required
        If UBound($aLocales) <= $aLocales[0] Then
            ReDim $aLocales[UBound($aLocales) * 2]
        EndIf
        $aLocales[$aLocales[0]] = $iLocale
    EndIf
Next
; Remove any unused elements
ReDim $aLocales[$aLocales[0] + 1]

; just for display
Global $aShortMonths[$aLocales[0]][13]

; Loop though LCIDs
For $i = 1 To $aLocales[0]
    ; Convert to decimal
    $iLCID = Dec($aLocales[$i])
    ; Get language definition
    $aShortMonths[$i - 1][0] = _WinAPI_GetLocaleInfo($iLCID, 0x5C)
    ; Get short months
    For $j = 0 To 11
        $aShortMonths[$i - 1][$j + 1] = _WinAPI_GetLocaleInfo($iLCID, $LOCALE_SABBREVMONTHNAME1 + $j)
    Next
Next
; Sort on language
_ArraySort($aShortMonths)
; And here we have them!
_ArrayDisplay($aShortMonths, "", Default, 8)

Now if you know the language set for the log file you can easily find out the short months used.

Edit 3: The @OSLang & @KBLayout macros could help you determine the language.

Edited by Melba23

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

 

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.

×
×
  • Create New...