Listview date format

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chngrcn
Posts: 190
Joined: 29 Feb 2016, 08:55

Listview date format

14 Sep 2018, 03:32

Code: Select all

Gui, Add, DateTime, x10 y+10 h20 w90 vDate1
Gui, Add, ListView, grid x10 w150 h170 vLV gLV -Multi, DATE1
Gui, Show, w200 h250

LV:
Gui, Submit, NoHide

LV_Add("", "02/08/2018")
LV_Add("", "12/09/2002")
LV_Add("", "18.05.2007")
LV_Add("", "24.02.2013")
LV_Add("", "31/12/2011")
LV_Add("", "14.09.2018")
LV_Add("", "14/09/2018")

LV_ModifyCol(1, 70)
;~ LV_ModifyCol(1, 70)
  
return

Hello

If I select any line in the ListView,
I want the datetime content to be the same with the format of the data.
also show today's date in dd/MM/yyyy format when you open the GUI.
Thank you for your help.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Listview date format

14 Sep 2018, 09:37

Try this:

Code: Select all

#NoEnv
#SingleInstance, Force

    Gui, Add, DateTime, x10 y+10 h20 w90 vDate1
    Gui, Add, ListView, Grid x10 w150 h170 vLV gLV, DATE1
    Gui, Show, w200 h250

    LV_Add("", "02/08/2018")
    LV_Add("", "12/09/2002")
    LV_Add("", "18.05.2007")
    LV_Add("", "24.02.2013")
    LV_Add("", "31/12/2011")
    LV_Add("", "14.09.2018")
    LV_Add("", "14/09/2018")

Return

GuiClose:
GuiEscape:
ExitApp



LV:
    LV_GetText(UserChoice, LV_GetNext())

    ChosenDate := SubStr(UserChoice, 7, 4) ; YYYY
                . SubStr(UserChoice, 4, 2) ; MM
                . SubStr(UserChoice, 1, 2) ; DD

    GuiControl,, Date1, %ChosenDate%

Return
I hope that helps.
garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: Listview date format

14 Sep 2018, 10:05

thank you wolf_II , I needed altsubmit
Gui, Add, ListView, Grid x10 w150 h170 vLV gLV +altsubmit, DATE1
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Listview date format

14 Sep 2018, 10:10

garry wrote:thank you wolf_II , I needed altsubmit
Gui, Add, ListView, Grid x10 w150 h170 vLV gLV +altsubmit, DATE1
Nice, thank you, too.
Now we get responses to single clicks.
garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: Listview date format

14 Sep 2018, 10:31

@wolf_II , sorry , didn't realized , your script works with doubleclick ... :)
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Listview date format

14 Sep 2018, 10:44

Yeah, I always forget that too.
chngrcn
Posts: 190
Joined: 29 Feb 2016, 08:55

Re: Listview date format

17 Sep 2018, 07:07

wolf_II wrote:Try this:

Code: Select all

#NoEnv
#SingleInstance, Force

    Gui, Add, DateTime, x10 y+10 h20 w90 vDate1
    Gui, Add, ListView, Grid x10 w150 h170 vLV gLV, DATE1
    Gui, Show, w200 h250

    LV_Add("", "02/08/2018")
    LV_Add("", "12/09/2002")
    LV_Add("", "18.05.2007")
    LV_Add("", "24.02.2013")
    LV_Add("", "31/12/2011")
    LV_Add("", "14.09.2018")
    LV_Add("", "14/09/2018")

Return

GuiClose:
GuiEscape:
ExitApp



LV:
    LV_GetText(UserChoice, LV_GetNext())

    ChosenDate := SubStr(UserChoice, 7, 4) ; YYYY
                . SubStr(UserChoice, 4, 2) ; MM
                . SubStr(UserChoice, 1, 2) ; DD

    GuiControl,, Date1, %ChosenDate%

Return
I hope that helps.

dear wolf
First of all thank you for your help.
Exactly what I want, I want to reflect the "datetime" box with the format in the selected row.

so,
the data in the "datetime" box should be 02/08/2018 when I select 02/08/2018 from the list
or
When I select 18.05.2018 from the list, the data in the "datetime" box should be 18.05.2018

Between the date "." and "/" with the signs should do.
Thank you.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Listview date format

17 Sep 2018, 08:08

I had a look at changing the (Customformat) of DateTime control. I have not yet found a built-in way to do so.

There is Sendmessage also. In my understanding, OOPS ... typo in my vars.
There is Sendmessage to help out.

Example:
  • does NOT work for ANSI
  • 32/64 bits Unicode OK

Code: Select all

#NoEnv
#SingleInstance, Force

    Gui, Add, DateTime, x10 y+10 h20 w90 vDate1 HWNDhDTM
    Gui, Add, ListView, Grid x10 w150 h170 vLV gLV, DATE1
    Gui, Show, w200 h250

    LV_Add("", "02/08/2018")
    LV_Add("", "12/09/2002")
    LV_Add("", "18.05.2007")
    LV_Add("", "24.02.2013")
    LV_Add("", "31/12/2011")
    LV_Add("", "14.09.2018")
    LV_Add("", "14/09/2018")

Return

GuiClose:
ExitApp



LV:
    LV_GetText(UserChoice, LV_GetNext())

    ChosenDate := SubStr(UserChoice, 7, 4) ; YYYY
                . SubStr(UserChoice, 4, 2) ; MM
                . SubStr(UserChoice, 1, 2) ; DD

    NewFormat := (UserChoice ~= "/.*/" ? "dd/MM/yyyy" : "dd.MM.yyyy")
    SendMessage, 0x1032, 0, &NewFormat,, ahk_id %hDTM% ; DTM_SETFORMATW

    GuiControl,, Date1, %ChosenDate%

Return
garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: Listview date format

17 Sep 2018, 10:58

@wolf_II , thank you, works fine
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Listview date format

17 Sep 2018, 11:10

fix to work in all flavours of AHK:

Code: Select all

    Set_Format := (A_IsUnicode ? 0x1032 : 0x1005) ; DTM_SETFORMAT (A/W)
    NewFormat := (UserChoice ~= "/.*/" ? "dd/MM/yyyy" : "dd.MM.yyyy")
    SendMessage, % Set_Format,, &NewFormat,, ahk_id %hDTM%
garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: Listview date format

17 Sep 2018, 13:15

fix to work in all flavours of AHK
thanx again for optimizing
chngrcn
Posts: 190
Joined: 29 Feb 2016, 08:55

Re: Listview date format

19 Sep 2018, 02:31

wolf_II wrote:fix to work in all flavours of AHK:

Code: Select all

    Set_Format := (A_IsUnicode ? 0x1032 : 0x1005) ; DTM_SETFORMAT (A/W)
    NewFormat := (UserChoice ~= "/.*/" ? "dd/MM/yyyy" : "dd.MM.yyyy")
    SendMessage, % Set_Format,, &NewFormat,, ahk_id %hDTM%
dear wolf

where necessary to put this code and run it;
When I double-click on Listview, it's today's date.

Can you share the code as a whole?
I'm making a mistake?
If so, as you say, should this be the case?

Code: Select all

#NoEnv
#SingleInstance, Force

    Gui, Add, DateTime, x10 y+10 h20 w90 vDate1 HWNDhDTM
    Gui, Add, ListView, Grid x10 w150 h170 vLV gLV, DATE1
    Gui, Show, w200 h250

    LV_Add("", "02/08/2018")
    LV_Add("", "12/09/2002")
    LV_Add("", "18.05.2007")
    LV_Add("", "24.02.2013")
    LV_Add("", "31/12/2011")
    LV_Add("", "14.09.2018")
    LV_Add("", "14/09/2018")

Return

GuiClose:
ExitApp



LV:
    LV_GetText(UserChoice, LV_GetNext())
    ChosenDate := SubStr(UserChoice, 7, 4) ; YYYY
                . SubStr(UserChoice, 4, 2) ; MM
                . SubStr(UserChoice, 1, 2) ; DD

	Set_Format := (A_IsUnicode ? 0x1032 : 0x1005) ; DTM_SETFORMAT (A/W)
    NewFormat := (UserChoice ~= "/.*/" ? "dd/MM/yyyy" : "dd.MM.yyyy")
    SendMessage, % Set_Format,, &NewFormat,, ahk_id %hDTM%

    ;~ NewFormat := (UserChoice ~= "/.*/" ? "dd/MM/yyyy" : "dd.MM.yyyy")
    ;~ SendMessage, 0x1032, 0, &NewFormat,, ahk_id %hDTM% ; DTM_SETFORMATW
    ;~ GuiControl,, Date1, %ChosenDate%

Return
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Listview date format

19 Sep 2018, 02:37

Sorry, I was not clear.

Code: Select all

#NoEnv
#SingleInstance, Force

    Gui, Add, DateTime, x10 y+10 h20 w90 vDate1 HWNDhDTM
    Gui, Add, ListView, Grid x10 w150 h170 vLV gLV, DATE1
    Gui, Show, w200 h250

    LV_Add("", "02/08/2018")
    LV_Add("", "12/09/2002")
    LV_Add("", "18.05.2007")
    LV_Add("", "24.02.2013")
    LV_Add("", "31/12/2011")
    LV_Add("", "14.09.2018")
    LV_Add("", "14/09/2018")

Return

GuiClose:
ExitApp



LV:
    LV_GetText(UserChoice, LV_GetNext())
    ChosenDate := SubStr(UserChoice, 7, 4) ; YYYY
                . SubStr(UserChoice, 4, 2) ; MM
                . SubStr(UserChoice, 1, 2) ; DD

	Set_Format := (A_IsUnicode ? 0x1032 : 0x1005) ; DTM_SETFORMAT (A/W)
    NewFormat := (UserChoice ~= "/.*/" ? "dd/MM/yyyy" : "dd.MM.yyyy")
    SendMessage, % Set_Format,, &NewFormat,, ahk_id %hDTM%
    GuiControl,, Date1, %ChosenDate%

Return
The format gets set to what you click. The patch was aimed at supporting ANSI as well as Unicode.
chngrcn
Posts: 190
Joined: 29 Feb 2016, 08:55

Re: Listview date format

19 Sep 2018, 02:58

wolf_II wrote:Sorry, I was not clear.

Code: Select all

#NoEnv
The format gets set to what you click. The patch was aimed at supporting ANSI as well as Unicode.
Dear wolf.
one last thing, I want the format in the "Datetime" object to be continuous dd/MM/yyyy after the gui is turned on or on. How can we provide this? Thank you.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Listview date format

19 Sep 2018, 03:07

the data in the "datetime" box should be 02/08/2018 when I select 02/08/2018 from the list
When I select 18.05.2018 from the list, the data in the "datetime" box should be 18.05.2018
I tried to solve this problem. Does it work for you?
chngrcn
Posts: 190
Joined: 29 Feb 2016, 08:55

Re: Listview date format

19 Sep 2018, 03:11

wolf_II wrote:
the data in the "datetime" box should be 02/08/2018 when I select 02/08/2018 from the list
When I select 18.05.2018 from the list, the data in the "datetime" box should be 18.05.2018
I tried to solve this problem. Does it work for you?
I want the format in the "Datetime" object to be continuous dd/MM/yyyy
When the datetime object is opened, it should be in dd/MM/yyyy format.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: catquas, Google [Bot], jpsala and 160 guests