Jump to content
Sign in to follow this  
keilamym

Datediff?

Recommended Posts

keilamym

i need just a little assistance.

when i do a datediff calculation to a variable, can i use the datdif value in an "if then" statement.

example.

i want to pull the date of a file and put it into a variable

use the datedif and date datecalc funtions to calculate what the date was 5 days ago.

using the IF statement, compare the two dates and if the file date is older than the datecalc value by 5 days, then i want to run a command on the workstation.

since the date format is yyyy,mm,dd, i'm not sure if autoit will calculate the dates correctly.

any assistance would be appreciated.

Keilamym

Share this post


Link to post
Share on other sites
Jos

i need just a little assistance.

when i do a datediff calculation to a variable, can i use the datdif value in an "if then" statement.

example.

i want to pull the date of a file and put it into a variable

use the datedif and date datecalc funtions to calculate what the date was 5 days ago.

using the IF statement, compare the two dates and if the file date is older than the datecalc value by 5 days, then i want to run a command on the workstation.

since the date format is yyyy,mm,dd, i'm not sure if autoit will calculate the dates correctly.

any assistance would be appreciated.

Keilamym

_DateDiff()/_DateAdd() can handle the input format:

"yyyy/mm/dd[ hh:mm[:ss]]" or "yyyy/mm/dd[Thh:mm[:ss]]"

"yyyy-mm-dd[ hh:mm[:ss]]" or "yyyy-mm-dd[Thh:mm[:ss]]"

"yyyy.mm.dd[ hh:mm[:ss]]" or "yyyy.mm.dd[Thh:mm[:ss]]"

If you want to know today-5 then you want to use _DateAdd("d",-5,_NowCalcDate())

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
keilamym

_DateDiff() can handle the input format:

"yyyy/mm/dd[ hh:mm[:ss]]" or "yyyy/mm/dd[Thh:mm[:ss]]"

"yyyy-mm-dd[ hh:mm[:ss]]" or "yyyy-mm-dd[Thh:mm[:ss]]"

"yyyy.mm.dd[ hh:mm[:ss]]" or "yyyy.mm.dd[Thh:mm[:ss]]"

If you want to know today-5 then you want to use _DateAdd("d",-5,_NowCalcDate())

jdbe..

thanks.. i've complete the portion of the script that tells me what the a date - 5 days will be, but can the if then statement calculate the different.

if the file date is more than 5 days older than todays date, then "do this"

Thanks

Share this post


Link to post
Share on other sites
SmOke_N

i need just a little assistance.

when i do a datediff calculation to a variable, can i use the datdif value in an "if then" statement.

example.

i want to pull the date of a file and put it into a variable

use the datedif and date datecalc funtions to calculate what the date was 5 days ago.

using the IF statement, compare the two dates and if the file date is older than the datecalc value by 5 days, then i want to run a command on the workstation.

since the date format is yyyy,mm,dd, i'm not sure if autoit will calculate the dates correctly.

any assistance would be appreciated.

Keilamym

This is how _DateDiff() with #include <date.au3> works:

;===============================================================================

;

; Description: Returns the difference between 2 dates, expressed in the type requested

; Parameter(s): $sType - returns the difference in:

; d = days

; m = Months

; y = Years

; w = Weeks

; h = Hours

; n = Minutes

; s = Seconds

; $sStartDate - Input Start date in the format "YYYY/MM/DD[ HH:MM:SS]"

; $sEndDate - Input End date in the format "YYYY/MM/DD[ HH:MM:SS]"

; Requirement(s): None

; Return Value(s): On Success - Difference between the 2 dates

; On Failure - 0 and Set

; @ERROR to: 1 - Invalid $sType

; 2 - Invalid $sStartDate

; 3 - Invalid $sEndDate

; Author(s): Jos van der Zande

; Note(s):

;

;===============================================================================

Edit:

:)... man I was reading it and didn't bother to refresh to see if anyone had posted already... too slowwwww.

Edited by SmOke_N

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
Jos

jdbe..

thanks.. i've complete the portion of the script that tells me what the a date - 5 days will be, but can the if then statement calculate the different.

if the file date is more than 5 days older than todays date, then "do this"

Thanks

Something like this?

#include<date.au3>
$n_tFile = "your file name"
$n_Fdate = FileGetTime($n_tFile,1)
$sdate=$n_Fdate[0] & "/" & $n_Fdate[1] & "/" & $n_Fdate[2] & " " &  $n_Fdate[3] & ":" & $n_Fdate[4] & ":" & $n_Fdate[5]
$edate=_NowCalc()
If _DateDiff ('d',$sdate,$eDate) > 5 then
;
EndIf
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
keilamym

Something like this?

#include<date.au3>
$n_tFile = "your file name"
$n_Fdate = FileGetTime($n_tFile,1)
$sdate=$n_Fdate[0] & "/" & $n_Fdate[1] & "/" & $n_Fdate[2] & " " &  $n_Fdate[3] & ":" & $n_Fdate[4] & ":" & $n_Fdate[5]
$edate=_NowCalc()
If _DateDiff ('d',$sdate,$eDate) > 5 then
;
EndIf

thanks this worked perfectly.. i had to change the paramerters to look for the last accessed date...

thanks again.

Edited by keilamym

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.