Page 1 of 1 1
Topic Options
#211171 - 2016-03-07 06:07 PM How to get the date for Monday
shayaan Offline
Just in Town

Registered: 2016-03-07
Posts: 1
Loc: NJ
My predecessor created a script that generates files like this

MMDDYYYY-@USERIDAM.txt

MMDDYYYY-@USERIDPM.txt

@USERID is the Windows AD name

The date of the file is the Monday of each week of the year

Example

03072016-johnsmithAM.txt
03072016-johnsmithPM.txt

I need to create a script that will delete the file for the current week (not the weeks in the future)

I am not sure how to do this in Kix

Top
#211173 - 2016-03-07 06:45 PM Re: How to get the date for Monday [Re: shayaan]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4574
Loc: USA
When will you be running the script to delete the files, (while the files are being created?, only on Mondays? every day?, a whole different script? There's a lot of ways to do this but determining when you will be doing it might direct us a in different path.

Also, I dont understand "(not the weeks in the future)".
_________________________
(... better days ahead)

Top
#211175 - 2016-03-08 03:51 AM Re: How to get the date for Monday [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
If I understand this.. you want to find the date of "Monday" from the current week, so that come, say Thursday, you can delete Monday's file?

It's all about time arithmetic...

The @DAY function returns the number of days since Sunday, so Monday is 1, Tuesday is 2, etc..

Each day has 86,400 seconds, and seconds is a standard way of expressing time values, called a "cTime". Technically, it's the number of seconds since an "Epoch" (an artificial "beginning of time", like Jan 1, 1900).

The TimeConvert UDF converts a date/time string to a cTime value and cTime values back to date/time strings. The TimeConvert UDF uses a standard epoch value, but you can define your own to use smaller values, like "@YEAR + '/01/01'".

So - what was the date this past Monday? How can I use that to create the file name to delete? Here's a working example using the TimeConvert UDF.
 Code:
$Today  = TimeConvert(@DATE + ' 00:00:00')	; Get the cTime for today at midnight

$DDay   = (Val(@WDAYNO) - 1) * 86400		; Calculate the number of seconds since Monday

$Monday = TimeConvert($Today - $DDay)		; Calculate the cTime for Monday by subtracting the elapsed seconds

' Today: ' @DATE ' / ' $Today ?			; show the Today cTime (debugging)
'  DDay: ' $DDay ?				; show the elapsed secs (debugging)
'Monday: ' Split($Monday, ' ')[0] ?		; show the date for Monday (debugging)

; reformat the date into the computer-unfriendly format ;)
$FileDate = SubStr($Monday, 6, 2) + SubStr($Monday, 9, 2) + Left($Monday, 4)

; Delete the file(s) from Monday
'Deleting files from ' $FileDate ?
Del $FileDate + '*.txt'				; wildcard file delete for matching dates
The same idea can be used for any day, and for longer periods (1 week = 86400*7 seconds)

Glenn

PS - if you want to use TimeConvert, you can get the latest version from the Kixtart pages of my web site - over 200 UDFs are available.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#211177 - 2016-03-08 04:15 AM Re: How to get the date for Monday [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
BTW - Welcome to KORG!

Where abouts in Joisey are ya? Bergen County here, near Hackensack. \:D

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 937 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.027 seconds in which 0.01 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org