Jump to content

Help with script that truncates date, and fixing short date?


Recommended Posts

Good Morning!  Been a long time.

There are 2 things that need fixing and I'm not able to (still not a programmer, though I can fix simple things easily enough! LOL):

#include <Date.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include<_My_DATE.au3>     ; my date, time conventions, etc.
#include <WindowsConstants.au3>
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon(@ScriptDir & "\0- DATE PICKER (2cb).ico")     ; changes the icon displayed in the systray
;-------------------------------------------------------------------------------------------------------------------------


;=========================================================================
Global $GUIboxTitle  = "Date Picker:"
Global $DateFormat   = "ddd.MMM.dd.yyyy"
$BoxIcon             = @ScriptDir & "\0- DATE PICKER (2cb).ico"
;-------------------------------------------------------------------------
;$Button1_Text         = "Create folder and send date to clipboard ..."
$Button1_Text         = "Send date to the clipboard ..."
;-------------------------------------------------------------------------
; where text is not needed in either Prefix or Suffix - i.e., before or after the date - then just leave blank by using "" (no text in between quotes).
$DateNameText_PREFIX  = ""
$DateNameText_SUFFIX  = "- "
;=========================================================================


Global $sPath         = "", $sDateParams
Global $hGUI = GUICreate($GUIboxTitle, 325, 250, 325, 340)     ; width, height, left, top (this determines size of entire GUI box)

Global $date = GUICtrlCreateDate("", 10, 10, 200, 20)     ; calendar pulldown box
GUICtrlSendMsg($date, 0x1032, 0, $DateFormat) ; $DTM_SETFORMAT

Global $hLabel1 = GUICtrlCreateLabel("", 10,  50, 300, 20)
Global $hLabel2 = GUICtrlCreateLabel("", 10,  80, 300, 20)
Global $hLabel3 = GUICtrlCreateLabel("", 10, 110, 300, 20)
Global $hLabel4 = GUICtrlCreateLabel("", 10, 140, 300, 20)

;Global $DateChooseButton = GUICtrlCreateButton("Create folder and send date to clipboard ...", 10, 200, 250, 30)
;Global $DateChooseButton = GUICtrlCreateButton("Create folder here (also sends date to clipboard) ...", 10, 200, 300, 30)     ; left, top, width, height (location of button)
Global $DateChooseButton = GUICtrlCreateButton($Button1_Text, 10, 200, 300, 30)     ; left, top, width, height (location of button)


;Global $FolderChooseButton = GUICtrlCreateButton("Select folder", 10, 170, 250, 30)
;Global $FolderChooseButton = GUICtrlCreateButton("1.  Select folder ...", 10, 170, 450, 30)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")


$sDateParams = _GetDate($date, $hLabel1)
GUISetIcon($BoxIcon)     ; this changes the GUI icon in upper left-hand corner + GUI taskbar icon to your chosen one
GUISetState()


While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
;       Case $FolderChooseButton
;            $sPath = FileSelectFolder("Select folder", "" , 7 , @DesktopDir, $hGUI)
;            GUICtrlSetData($FolderChooseButton, "1.  Path selected:  ''" & $sPath & "''")
        Case $DateChooseButton
            ;================================================================================
            $ChosenDateFormat = $DateNameText_PREFIX & $sDateParams & $DateNameText_SUFFIX
            ;================================================================================
;           $sDateParams = _GetDate($date, $hLabel1)
;           ClipPut($sDateParams)
            ClipPut($ChosenDateFormat)
_BEEP()
;           If FileExists($sPath) = 1 Then
;               FileChangeDir($sPath)
;               DirCreate(@ScriptDir & "\" & $ChosenDateFormat)
;           EndIf
            ;-------------------------------------------------------------
    EndSwitch

WEnd

Func _GetDate($cDate, $clabel)
    ;=============================================================
    Local $parametersDate = GUICtrlRead($cDate)
    ;=============================================================

    ;use StringRight() to get the three character weekday abbrev. from the selected date.
    Local $sWkDay = StringRight($parametersDate, 3)

    ;get the two character weekday abbreviation from the three-character weekday abbreviation.
    Local $ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", $sWkDay), 2)

    ;replace the three character weekday, with the two character weekday.
    $parametersDate = StringReplace($parametersDate, $sWkDay, $ShortDayMyFormat)
    GUICtrlSetData($clabel, "Chosen date above, formatted as:  " & $parametersDate)
    Return $parametersDate
    ;-------------------------------------------------------------
EndFunc


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    Switch DllStructGetData($tNMHDR, "IDFrom")
        Case $date
            Switch DllStructGetData($tNMHDR, "Code")
                Case $DTN_DATETIMECHANGE ; Sent by a date and time picker (DTP) control whenever a change occurs
                    $sDateParams = _GetDate($date, $hLabel1)
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

1.  Truncating:

If I pick today's date, I get this:   Mon.Nov.06.2- 

And I've never figured out where to fix the length of the date as the last 3 digits in the date are cut off.

 

2.  My short date format isn't captured, and don't know how to fix.

Short date works when I use other scripts but when I change it to this particular format, it stops working and I don't know why <chagrin>:

The line in question is this one:

Local $ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", $sWkDay), 2)

 

Thank you!  Any help appreciated!

Have a great day.  :oD

Link to comment
Share on other sites

The script it does exactly what it's suppose to do:

Local $sWkDay = StringRight($parametersDate, 3)

This mean take 3 characters from the right of Mon.Nov.06.2023.

And this line does exactly nothing and will return an empty string.

Local $ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", $sWkDay), 2)

So when you replace $sWkDay with nothing, basically you strip the last 3 characters from the original string:

$parametersDate = StringReplace($parametersDate, $sWkDay, $ShortDayMyFormat)

You probably want to get 3 characters from the left not from the right, so use:

Local $sWkDay = StringLeft($parametersDate, 3)

 

When the words fail... music speaks.

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...