Jump to content

Recommended Posts

Hi

I know how to set Date Formats to my preference.

However, I want a DTP that shows ONLY months, annually. The idea is that the user selects the relevant month, then I can use start / end date from there. Avoid multiple date selections for 1 July 20xx & 31 July 20xx. Just one click -> July 20xx.

Problem is that the Selector drills down to the day level.  How do I stop it from going that level lower? I only want the month (to be available for selection), not individual days.

Advice, please?

dto_mmm.png.f31599e8aa58224a44c4deee92d546d4.png

; Script Start - Add your code below here
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>

Example()

Func Example()
    Local $hDTP

    ; Create GUI
    GUICreate("DateTimePick Set Format", 400, 300)
    $hDTP = GUICtrlGetHandle(GUICtrlCreateDate("", 2, 6, 220))

    $hDTP2 = GUICtrlGetHandle(GUICtrlCreateDate("", 2, 40, 220))

    GUISetState(@SW_SHOW)

    ; Set the display format
    _GUICtrlDTP_SetFormat($hDTP, "ddd MMM dd, yyyy hh:mm ttt")

_GUICtrlDTP_SetFormat($hDTP2, "MMM") ; <<<< my attempt

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

That "Today: 2019-07-31" could simply become "Current Month: July" 

I need current month and year only.

Thanks

Skysnake

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Link to post
Share on other sites

Here something to start you up :)

#include <Constants.au3>
#include <GUIConstants.au3>

Opt("MustDeclareVars", 1)

MsgBox ($MB_SYSTEMMODAL,"",MonthCalendar())

Func MonthCalendar($iLeft = -1, $iTop = -1)
  Local Const $asMonth[12] = ["Jan", "Fév", "Mar", "Avr", "Mai", "Juin", "Juil", "Août", "Sep", "Oct", "Nov", "Déc"]
  Local Const $cHighlight = 0xD6E0FF

  Local $hGUI = GUICreate("", 250, 150, $iLeft, $iTop, $WS_POPUP + $WS_BORDER)
  Local $iPrev = GUICtrlCreateLabel(ChrW(0x25C0), 25, 15, 25, 25, $SS_CENTER)
  GUICtrlSetFont(-1, 16)
  Local $iNext = GUICtrlCreateLabel(ChrW(0x25B6), 205, 15, 25, 25, $SS_CENTER)
  GUICtrlSetFont(-1, 16)
  Local $iYear = GUICtrlCreateLabel(@YEAR, 100, 21, 50, 25, $SS_CENTER)
  Local $aiMonth[12], $i = 0
  For $y = 0 To 2
    For $x = 0 To 3
      $aiMonth[$i] = GUICtrlCreateLabel($asMonth[$i], 50 * $x + 38, 30 * $y + 50, 30, 20, $SS_LEFT + $SS_CENTERIMAGE)
      GUICtrlSetFont(-1, 10)
      $i += 1
    Next
  Next
  $i = Int(@MON) - 1
  GUICtrlSetBkColor($aiMonth[$i], $cHighlight)

  Local $iOK = GUICtrlCreateDummy ()
  Local $aAccelKeys[1][2] = [["{ENTER}", $iOK]]
  GUISetAccelerators($aAccelKeys)
  GUISetState(@SW_SHOW)

  Local $nMsg

  While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
      Case $GUI_EVENT_CLOSE
        GUIDelete ()
        Return ("")
      Case $iPrev
        GUICtrlSetData($iYear, GUICtrlRead($iYear) - 1)
      Case $iNext
        GUICtrlSetData($iYear, GUICtrlRead($iYear) + 1)
      Case $aiMonth[0] To $aiMonth[11]
        If $i = $nMsg - $aiMonth[0] Then ContinueLoop
        GUICtrlSetBkColor($nMsg, $cHighlight)
        GUICtrlSetBkColor($aiMonth[$i], Default)
        $i = $nMsg - $aiMonth[0]
      Case $iOK
        Local $sReturn = GUICtrlRead($iYear) & "|" & $i + 1
        GUIDelete()
        Return $sReturn
    EndSwitch
  WEnd
EndFunc   ;==>MonthCalendar

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Skysnake
      Hi
      This is a request to streamline various Date and Time functions.  (PS My ability to log a ticket appears to be limited by an uncooperative server).
      Let met start by saying these functions all work.  This is not an error report.
      The documentation appears accurate.
       
      My problem started here:
      page autoit.chm::/html/libfunctions/_DateAdd.htm
      contains "$sDate     Initial date in the format YYYY/MM/DD[ HH:MM:SS]"
       
      This is in stark contrast to eg 
      _DateIsValid
      "This function takes a date input in one of the following formats:
      "yyyy/mm/dd[ hh:mm[:ss]]" or "yyyy/mm/dd[Thh:mm[:ss]]"
      "yyyy-mm-dd[ hh:mm[:ss]]" or "yyyy-mm-dd[Thh:mm[:ss]]"
      "yyyy.mm.dd[ hh:mm[:ss]]" or "yyyy.mm.dd[Thh:mm[:ss]]""
      or 
      my own personal, do-anything option
      _GUICtrlDTP_SetFormat
      I understand that DTP and DateTime is not exactly the same.  That is not the issue.
      My problem is with being able to create and TEST a valid date in at least 3 different formats, but not being able to use additional functions on such a valid date.  Assume my format is  yyyy-mm-dd based on the  "yyyy-mm-dd[ hh:mm[:ss]]" or "yyyy-mm-dd[Thh:mm[:ss]]" _DateIsValid() function.  I now have a valid function, but cannot readily use it with any of the internal DateTime functions.
      Would it be possible to consider modifying the existing functions to work with the standard formats.  Put simply, if a format is accepted by _DateIsValid(), all other DateTime formats should work with same date (format) directly.
      Once I have an accepted date, I want to use all internal functions on it. 
      Thank you for your kind attention.
      Skysnake
×
×
  • Create New...