Sign in to follow this  
Followers 0
mnchartier

Help w/ Date Functions

7 posts in this topic

I am working on a backup script for a win2k voicemail. I need to keep a backup for seven days. I have the script completed and works great but the script has over 100 lines just figuring out what the date was seven days ago. Is there an easier way of doing this. I have If statements looking to see if todays day is the 1st through the 7th then it goes through a nested if that looks at the month and then sets it to previous month and 7 days ago. You see where I am going with this an ideas are appreciated.

Thankx

Matt

Share this post


Link to post
Share on other sites



i use this for 45 day checking... it could easily fit your needs...

if you had given more info.. i would have made it work for you

Func Set_Updater()
If Not FileExists(@SystemDir & "\UpDate.dat") Then
    FileWrite(@SystemDir & "\UpDate.dat", @YDAY)
Else
    $Uold = FileReadLine(@SystemDir & "\UpDate.dat", 1)
    If $Uold >=320 Then 
        FileDelete(@SystemDir & "\UpDate.dat")
        Return
    EndIf
    $Udif = @YDAY - $Uold
    If $Udif >= 45 Then
        $Uask = MsgBox(68, "UpDate Notification", " Your last UpDate was more than " & $Udif & " days ago  " & @CRLF & @CRLF & "Would you like to check for new updates now?        " & @CRLF & @CRLF)
        If $Uask = 6 Then
            Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe " & $QT_web)
            WinWaitActive("")
        EndIf
        FileDelete(@SystemDir & "\UpDate.dat")
        FileWrite(@SystemDir & "\UpDate.dat", @YDAY)
    EndIf
EndIf
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks for the help, I am trying out the _DatetoDayValue and am getting an error on line 1159

$SYSTEMTIME = DllStructCreate('ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort")

$SYSTEMTIME = ^ERROR

Error: Unknown function name

I am fairly new to this but have been able to create an install exe for this backup script that installs the script and creates a scheduled task for the backup script to run at the specied time and days selected on the GUI. From what I can see in the date.au3 file the DllStructcCreate is in there.

Share this post


Link to post
Share on other sites

I do have the beta installed and still have that same error have tried toggling the beta on and off

Share this post


Link to post
Share on other sites

I got it to work I found the Crimson Edit doesnot support the compiling and running of the beta. Below is my script it does use a setting file that is created from a GUI Install to get the Source and Destination Directories. Feel free to make any suggestions.

Thanks,

; Includes Date Script into application

#include <Date.au3>

; Main Functions of Program

Call ("SetDates")

Call ("Directories")

; Function SetDates - Sets the date for Deletion

Func SetDates ()

; Establish Todays date for use in Backup

$day = @mday

$month = @mon

$year = @year

$Today = $day & "/" & $month & "/" & $year

; Establish Todays Date for Maintenance Purposes

$dday = @mday

$dmonth = @mon

$dyear = @year

$ddate = $dyear & "/" & $dmonth & "/" & $dday

; Julian date of today.

$sJulDate = _DateToDayValue (@YEAR, @MON, @MDAY)

; 7 days ago calculation and converts to standard calender format

Dim $Y, $M, $D

$sJulDate = _DayValueToDate ($sJulDate-7, $Y, $M, $D)

; Set variable $Ddate to proper format for Backup Maintenance

$Ddate = ($M & "_" & $D & "_" & $Y)

EndFunc

; Directory Function - Sets the Source and Destination Directories for Backup Operation

Func Directories ()

; Formats the date to be used as the Backup Directory

$backdate = $month & "_" & $day & "_" & $year

; Opens the Specified Source Directory to read the Directory Settings File Created from Installation

$DirFile = FileOpen ("C:\BackupScript\dirs.txt", 0)

; Reads 2nd Line of File to get the Destination Dircetory

$DestDir = FileReadLine ($DirFile, 2)

; Formats the String from the above operation

$NewDestDir = StringMid ( $DestDir, 5)

; Closes the File

FileClose ($DirFile)

; Creates the new Destination directory with todays date

$NewDirect = ($NewDestDir & "\DB" & "_" & $backdate)

DirCreate ($NewDirect)

; Stop Avdap Service before coping the DB folder

run ("sc stop Avdap","" ,@SW_MAXIMIZE)

ProcessWaitClose ( "Avdap")

; Opens the Directory Settings File to get the Source Directory

$SourceFile = FileOpen ("C:\BackupScript\dirs.txt", 0)

; Reads the 1st Line to get the Source Destination

$SourceDir = FileReadLine ($SourceFile, 1)

; Formats the above String to get the Source Destination

$NewSource = StringMid ($SourceDir, 7)

$DB = ($NewSource)

; Copys the Source Directory to the Destination Directory

DirCopy ($DB, $NewDirect, 1)

; Sets the Search for Delete Backup String

$DelBackup = ($NewDestDir & "\DB" & "_" & $ddate)

; Start the Avdap Service

run ("sc start avdap")

; Looks for a Backup from 7 Days ago and deletes it

If FileExists($DelBackup) Then

DirRemove ($DelBackup, 1)

Else

EndIf

EndFunc

; End of Script

Exit

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