Jump to content
Sign in to follow this  
Diana (Cda)

How to subtract days from special format dates?

Recommended Posts

Diana (Cda)

I have this script with the special syntax of "$ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", _DateDayOfWeek(@WDAY,1) ), 2)" that I use in an effort to _try_ to keep file/folder names as short as possible while still providing valuable info. Sometimes that extra letter is all it takes <g>. This syntax was provided by a kind poster on this forum quite some time ago. It works just great. I usu. use it in a straightforward application.

However, I stumbled upon a behaviour of @WDAY and other date formats that if I subtract or add from them, they change the day, etc. i.e., when I use a script with @MDAY-2 today, it'll give me Friday's date. But I haven't had luck doing anything similar with the above special format. I tried just doing the same to the @WDAY code by changing the @WDAY above to, say, @WDAY-2 but that doesn't do the trick. Here's an example script:

;
; AutoIt 3x
;
#include <_PartitionLetters.au3>     ; this replaces drive letters
#include<_WEReplacement.au3>     ; references a Windows Explorer replacement program
AutoItSetOption("WinTitleMatchMode", 2)     ; this allows partial window titles to be valid!
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon("Shell32.dll", 21)     ; changes the icon displayed in the systray

;-----------------------------------------
#Include <Date.au3>
; Short day of the week, i.e., Monday = Mon
$ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", _DateDayOfWeek(@WDAY,1) ), 2)
;-----------------------------------------



;--------------------------------------------------------------------------------------------------
SplashTextOn("WAIT ...", @CRLF & "Please wait while the folder is created.", 350, 50, 250, 250, "Comic Sans MS","12","10") _
        ;  Make sure a "SplashOff()" is at end to turn off the splash screen. _
        ;  width, height, x pos, y pos, "fontname", "fontsz", "fontwt"
;--------------------------------------------------------------------------------------------------


DirCreate(@ScriptDir & "\USBbkp- " & @YEAR & "." & @MON & "." & @MDAY-2 & "." & $ShortDayMyFormat)

Sleep(100)
Send("{F5}")


Beep(500, 75)
Beep(1000, 50)
Beep(500, 75)
Beep(1000, 50)


;--------------------------------------------------------------------------------------------------
SplashOff()     ;  turns off Splash...On(...) above.
;--------------------------------------------------------------------------------------------------
8

Sleep(2000)


Exit     ; finished

DirCreate(@ScriptDir & "\USBbkp- " & @YEAR & "." & @MON & "." & @MDAY-2 & "." & $ShortDayMyFormat)
creates a folder for Friday but with no day, i.e., "Fr".

DirCreate(@ScriptDir & "\USBbkp- " & @YEAR & "." & @MON & "." & @MDAY-1 & "." & $ShortDayMyFormat)
creates one with yesterday's date, 26th, but also no day, "Sa", in title.

DirCreate(@ScriptDir & "\USBbkp- " & @YEAR & "." & @MON & "." & @MDAY & "." & $ShortDayMyFormat)
This is straightforward, and it does create a folder with both today's date, 27th, and day, "Sn".

Is there any way to change the special format to do the same, just with a subtraction somehow?

Thanks! :P

Share this post


Link to post
Share on other sites
SmOke_N

@MDAY-1

So if today was the first?

Also, I find it very very difficult to follow your post.

Before:

xxxxx

After:

xxxxx

Desired:

xxxxx

Would be much more helpful.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Diana (Cda)

@MDAY-1

So if today was the first?

Also, I find it very very difficult to follow your post.

Yes, I understand. Not only is it difficult to try to explain the problem, unless the scripts are tried, it's difficult to grasp the concept <g>.

So here goes, with the original script, with "DirCreate(@ScriptDir & "\USBbkp- " & @YEAR & "." & @MON & "." & @MDAY & "." & $ShortDayMyFormat)",

I get a folder labelled:

USBbkp- 2008.07.27.Sn
this is correct, obviously <g>.

"DirCreate(@ScriptDir & "\USBbkp- " & @YEAR & "." & @MON & "." & @MDAY-1 & "." & $ShortDayMyFormat)" produces

USBbkp- 2008.07.26.Sn
with incorrect day, "Sn". Should be "Sa".

"DirCreate(@ScriptDir & "\USBbkp- " & @YEAR & "." & @MON & "." & @MDAY-2 & "." & $ShortDayMyFormat)" produces

USBbkp- 2008.07.25.Sn
which should be "Fr".

@MDAY-x changes date but doing the same in the short day format doesn't work the same way:

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

just makes the folder come out with no day at all, though the rest of the script produces a new folder with right date.

The script is relative. "Today's" one produces today's date; "Yesterday's" script produces yesterday's, and "Two Days ago" makes a folder for 2 days ago. I only need those 3 since my backups never go make more than that. The latest will be on Sundays when I make Friday's backup. I just got so fed up of creating folders and typing out everything that I did these scripts up. Every bit of time saved pays back exponentially later on.

Hope that's clearer. Tough to get a point across with just written word <g>.

Cheers! :P

Share this post


Link to post
Share on other sites
SmOke_N

MsgBox(0, 0, SubWkDay(@WDAY, 0) & @CRLF & SubWkDay(@WDAY, 1))
Func SubWkDay($n_wkday, $n_sub)
    If $n_sub > 7 Then $n_sub = Mod($n_sub, 7)
    Local $n_day = $n_wkday - $n_sub
    If $n_day < 1 Then $n_day += 7
    Local $a_day[8] = ["", "Sn", "Mn", "Tu", "Wd", "Th", "Fr", "Sa"]
    Return $a_day[$n_day]
EndFunc
You'll need to figure out how to implement it.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.