Sign in to follow this  
Followers 0
Diana (Cda)

[Resolved, yeay!] Fix to personal day format, usually works ... ?

7 posts in this topic

#1 ·  Posted (edited)

I've looked at various date picking scripts in the forum and found one I could finally figure out how to work with. It does the job and excellently, except I'd like to change the day format to my own personal preference. A few years back I was given code that works all the time but it doesn't here and I don't know why.

Here's the working script:

#include <Date.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include<_My_DATE.au3>     ; my date, time conventions, etc.
#include <WindowsConstants.au3>


;=========================================================================
$GUIboxTitle  = "Date Picker:"
;$myDateFormat = "yyyy.MM.dd.ddd"; & $ShortDayMyFormat
$myDateFormat = "yyyy.MM.dd." & $ShortDayMyFormat
;=========================================================================

$hGUI = GUICreate($GUIboxTitle, 300, 250)

$date = GUICtrlCreateDate("", 10, 10, 200, 20)

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

$DateChooseButton = GUICtrlCreateButton("Create folder and send date to clipboard ...", 10, 200, 250, 30)

GUISetState()

GUICtrlSendMsg($date, 0x1032, 0, $myDateFormat)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $DateChooseButton
            ;=============================================================
            $parametersDate = GUICtrlRead($date)
            ;=============================================================
            GUICtrlSendMsg($date, 0x1032, 0, $myDateFormat)
;            GUICtrlSetData($hlabel1, GUICtrlRead($date))
            GUICtrlSetData($hlabel1, "Date chosen:  " & $parametersDate)
            ;-------------------------------------------------------------
            ClipPut($parametersDate)
            DirCreate($parametersDate)
            ;-------------------------------------------------------------
    EndSwitch
    
WEnd

The problem lies in the part that determines the date format output, the variable $myDateFormat.

The commented-out line above, with the actual format of "yyyy.MM.dd.ddd" returns a correct date.

My own format choice of $myDateFormat = "yyyy.MM.dd." & $ShortDayMyFormat gives weird results.

The $ShortDayMyFormat is code I was given years ago and has always worked up till now. This variable references this code for a listed UDF I use all the time:

$ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", _DateDayOfWeek(@WDAY,1) ), 2)
and that has always worked before. In this case, when I use it, rather than giving me, say, 2011.02.02.Wd for today, it gives 2011.02.02.W2, where W2 should be Wd.

Can anyone tell me what will work in this particular case? I really like this type of script for creating folders and using a date picker to use as part of the folder label but need my one-character shorter version for the days of the week.

Thanks! :)

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites



Can you shorten your problem description? Your UDF is not included that is why your code doesn't work.


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Your UDF is not included that is why your code doesn't work, etc.

Weeelllllll, UDFs generally aren't included <lol>. That's why they save space and writing.

All kidding aside, the UDF is correctly referenced, btw. It's in line at top as shown above in "#include<_My_DATE.au3> ; my date, time conventions, etc.". As you know, I would have gotten an error not an incorrect result if it weren't there, as is happening here. The variable from my UDF I copied above and I'll repeat it again here below; it's the line:

$ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", _DateDayOfWeek(@WDAY,1) ), 2)

As I mentioned, instead of giving me a ddd for Wd, for today, it's giving me a value of W2. I don't know why it's not working since I reference this UDF all the time in just this way and it's never failed before. Something else must/might be going on here which I can't for the life of me figure out.

$ShortDayMyFormat always returns Sn, Mn, Tu, Wd, Th, Fr, Sa instead of Sun, Mon, Tue, Wed, Thu, Fri, Sat when used in place of date format ddd.

Regardless. Just would like to know what will change ddd to Sn, Mn format rather than Sun, Mon, when the above $ShortDayMyFormat syntax is not working in this one case.

Thanks much. :)

p.s., I like your avatar! Pretty neat.

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Okay, guessing it's not so easy to answer. Have come back to this throughout day and kept trying. The weird output continues. Each successive day in date picker increments number. Tomorrow's date gives 2011.02.03.W3, Friday gives 2011.02.04.W4 rather than 2011.02.03.Th and 2011.02.04.Fr, respectively.

I hoped actual, original syntax given to me years ago could be fixed since it has worked for absolutely everything else; but I'm guessing that here something is interfering with correct results. If clean fix not possible, anyone know what can be used in place of ddd that ordinarily gives:

Mon, Tue, Wed, Thu, Fri, Sat, Sun
to get this instead:

Mn, Tu, Wd, Th, Fr, Sa, Sn

replacing the "ddd" in this type of date format?:

yyyy.MM.dd.ddd

Thanks much! :)

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites

Diana

you can't concatenate your abbreviated weekday to the datepicker DTM_SETFORMAT format message

it's limited to the formats in the help file under User Defined Functions Reference

for _GUICtrlDTP_SetFormat() in the GuiDate TimePicker Management section.

and listed here:

DTM_SETFORMAT

http://msdn.microsoft.com/en-us/library/aa452982.aspx

but you can use a modified version of your code to edit

the returned value from the datepicker as this example shows.

the datepicker can probably be modified with a 'callback' to have a two character weekday,

but that requires a substantial amount of code to implement.

as outlined in this MSDN page :http://msdn.microsoft.com/en-us/library/aa271528.aspx

#include <Date.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
;#include<_My_DATE.au3>     ; my date, time conventions, etc.
#include <WindowsConstants.au3>

;=========================================================================
$GUIboxTitle  = "Date Picker:"
$myDateFormat = "yyyy.MM.dd.ddd"
;=========================================================================
$sPath = ""
$hGUI = GUICreate($GUIboxTitle, 300, 250)

$date = GUICtrlCreateDate("", 10, 10, 200, 20)
GUICtrlSendMsg($date, 0x1032, 0, $myDateFormat) ; $DTM_SETFORMAT

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

$DateChooseButton = GUICtrlCreateButton("Create folder and send date to clipboard ...", 10, 200, 250, 30)
$FolderChooseButton = GUICtrlCreateButton("Select folder", 10, 170, 250, 30)

GUISetState()


While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $FolderChooseButton
            $sPath = FileSelectFolder("Select folder", "" , 7 , "C:\" , $hGUI)
            GUICtrlSetData($FolderChooseButton, "Path:  " & $sPath)
        Case $DateChooseButton
            ;=============================================================
            $parametersDate = GUICtrlRead($date)
            ;=============================================================

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

            ;get the two character weekday abbreviation from the three-character weekday abbreviation.
            $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($hlabel1, "Date chosen:  " & $parametersDate)
            ;-------------------------------------------------------------
            ClipPut($parametersDate)
            If FileExists($sPath) = 1 Then
                FileChangeDir($sPath)
                DirCreate($parametersDate);using workingdir here?
            EndIf
            ;-------------------------------------------------------------
    EndSwitch

WEnd

I see fascists...

Share this post


Link to post
Share on other sites

you can also have the date label updated immediately when a new date is selected,

then you just have to select a folder and copy to clipboard and create the folder

#include <Date.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
;#include<_My_DATE.au3>     ; my date, time conventions, etc.
#include <WindowsConstants.au3>

;=========================================================================
Global $GUIboxTitle  = "Date Picker:"
Global $myDateFormat = "yyyy.MM.dd.ddd"
;=========================================================================
Global $sPath = "", $sDateParams
Global $hGUI = GUICreate($GUIboxTitle, 300, 250)

Global $date = GUICtrlCreateDate("", 10, 10, 200, 20)
GUICtrlSendMsg($date, 0x1032, 0, $myDateFormat) ; $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 $FolderChooseButton = GUICtrlCreateButton("Select folder", 10, 170, 250, 30)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")


$sDateParams = _GetDate($date, $hLabel1)
GUISetState()


While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $FolderChooseButton
            $sPath = FileSelectFolder("Select folder", "" , 7 , "C:\" , $hGUI)
            GUICtrlSetData($FolderChooseButton, "Path:  " & $sPath)
        Case $DateChooseButton
            ;$sDateParams = _GetDate($date, $hLabel1)
            ClipPut($sDateParams)
            If FileExists($sPath) = 1 Then
                FileChangeDir($sPath)
                DirCreate($sDateParams);using workingdir here?
            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, "Date chosen:  " & $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

I see fascists...

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Wow, Rover, that's some really great work, there. Thank you! I suspected that the problem lay in intercepting the output and putting in the date format I needed but didn't realize where. And it's not even possible here. Makes sense. I don't particularly understand your workaround completely except in principle but I'm getting better at producing results even though I still don't always know what code does <g>.

Like always, we have to make things understandable to our own simpler knowledge, so hope you don't mind my slight modifications to make it easier for me to use/remember. Your second script works wonderfully as a generic file folder creator where format remains the same and allows me to have the script located in one place and where I just have to call it and navigate to folder in question. Folder paths turned out to be too long for the button so changed width, etc. Here is the modified version - which I hope doesn't make you cringe too much <lol>!:

#include <Date.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
;#include<_My_DATE.au3>     ; my date, time conventions, etc.
#include <WindowsConstants.au3>

;=========================================================================
Global $GUIboxTitle  = "Date Picker:"
Global $myDateFormat = "yyyy.MM.dd.ddd"
;=========================================================================
Global $sPath = "", $sDateParams
Global $hGUI = GUICreate($GUIboxTitle, 480, 250)     ; this determines size of entire GUI box

Global $date = GUICtrlCreateDate("", 10, 10, 200, 20)     ; calendar pulldown box
GUICtrlSendMsg($date, 0x1032, 0, $myDateFormat) ; $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("2.  Create folder and send date to clipboard ...", 10, 200, 450, 30)
;Global $FolderChooseButton = GUICtrlCreateButton("Select folder", 10, 170, 250, 30)   ; button too narrow, increase size
Global $FolderChooseButton = GUICtrlCreateButton("1.  Select folder ...", 10, 170, 450, 30)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")


$sDateParams = _GetDate($date, $hLabel1)
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
            ;$sDateParams = _GetDate($date, $hLabel1)
            ClipPut($sDateParams)
            If FileExists($sPath) = 1 Then
                FileChangeDir($sPath)
                DirCreate($sDateParams);using workingdir here?
            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, "Date chosen:  " & $parametersDate)
    GUICtrlSetData($clabel, "Chosen date and format will be:  " & $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

But the script I need the most is the one where I create regular and constant backups, etc., and frequently create folders to move files into. The folder names change with only date being constant factor. I keep these scripts within the main backup, etc., folders so no need to navigate anywhere as these are created via @ScriptDir. And I found a way to easily change folder name parameters with recycled versions of this script - so your code has been really cool to work with:

#include <Date.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
;#include<_My_DATE.au3>     ; my date, time conventions, etc.
#include <WindowsConstants.au3>

;=========================================================================
Global $GUIboxTitle  = "Date Picker:"
Global $DateFormat   = "yyyy.MM.dd.ddd"
;-------------------------------------------------------------------------
; 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).
$FldrNameText_PREFIX  = "TestPrefix- "
$FldrNameText_SUFFIX  = "- TestSuffix"
;=========================================================================
Global $sPath = "", $sDateParams
Global $hGUI = GUICreate($GUIboxTitle, 275, 250)     ; width; height - 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 and send date to clipboard ...", 10, 200, 250, 30)
;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)
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
            ;$sDateParams = _GetDate($date, $hLabel1)
            ClipPut($sDateParams)
;            If FileExists($sPath) = 1 Then
;                FileChangeDir($sPath)
                DirCreate(@ScriptDir & "\" & $FldrNameText_PREFIX & $sDateParams & $FldrNameText_SUFFIX)
 ;           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 and format will be:  " & $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

Thanks! Though I've inched along all these years, I still wonder when I'll get to the point where I can write stuff like the above all by myself. Maybe in another 6 years or so ... <lol>

(Gawd, I hope not!)

:)

Edited by Diana (Cda)

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  
Followers 0