Jump to content

Datediff?


Recommended Posts

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

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

_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

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 2 weeks later...

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...