Author |
Topic |
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-05 : 02:50:46
|
Hi,I am using the following javascript to find out if the file exists and then get the date of the file.Now I would like to return true or false if the date of the file is older than one week.How is this done please?Thanks//**********************************************************************// Java ActiveX Script//************************************************************************function Main(){ var filespec = DTSGlobalVariables("FTPROOT").value + "\\" + DTSGlobalVariables("FILE").Value; var f; var d var fso = new ActiveXObject("Scripting.FileSystemObject"); if ( fso.FileExists(filespec) == true); { f = fso.GetFile(filespec); d = f.DateLastModified; } DTSGlobalVariables("FileDateModified").Value = d; return(DTSTaskExecResult_Success); } |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-05 : 02:59:42
|
Is there any function like Datediff in JavaScript?Otherwise you can check like thisIf currentdate-d>=7 thentrueelsefalse MadhivananFailing to plan is Planning to fail |
 |
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-05 : 03:08:39
|
I have now modified it likek the following but there is an error on the getdate() line.//**********************************************************************// Java ActiveX Script//************************************************************************function Main(){ var filespec = DTSGlobalVariables("FTPROOT").value + "\\" + DTSGlobalVariables("FILE").Value; var f; var d var fso = new ActiveXObject("Scripting.FileSystemObject"); if ( fso.FileExists(filespec) == true); { f = fso.GetFile(filespec); d = f.DateLastModified; DTSGlobalVariables("FileDateModified").Value = d; if (getDated() - d > 7) { return(DTSTaskExecResult_Success); } } } |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-05 : 03:16:26
|
quote: if (getDated() - d > 7)
Should it be if (getDate() - d > 7) ?MadhivananFailing to plan is Planning to fail |
 |
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-05 : 03:18:19
|
yes, u r right. That is what I meant.But it does not work. It says object required.Thanks |
 |
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-05 : 03:33:12
|
I think I am one step forward now but still there is an object missing on the line --> if (dt.getDate() - d.getDate() < 7)Thanks//**********************************************************************// Java ActiveX Script//************************************************************************function Main(){ var filespec = DTSGlobalVariables("FTPROOT").value + "\\" + DTSGlobalVariables("FILE").Value; var f; var d; var fso = new ActiveXObject("Scripting.FileSystemObject"); if ( fso.FileExists(filespec) == true); { f = fso.GetFile(filespec); d = f.DateLastModified; DTSGlobalVariables("FileDateModified").Value = d; var dt = new Date(); var t_date = dt.getDate(); // Returns the day of the month var t_mon = dt.getMonth(); // Returns the month as a digit var t_year = dt.getFullYear(); // Returns 4 digit year if (dt.getDate() - d.getDate() < 7) { return(DTSTaskExecResult_Success); } } } |
 |
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-05 : 04:14:13
|
Even the DateDiff gives the same error (i.e. object required).Thanks//**********************************************************************// Java ActiveX Script//************************************************************************function Main(){ var filespec = DTSGlobalVariables("FTPROOT").value + "\\" + DTSGlobalVariables("FILE").Value; var f; var d; var fso = new ActiveXObject("Scripting.FileSystemObject"); if ( fso.FileExists(filespec) == true); { f = fso.GetFile(filespec); d = f.DateLastModified; DTSGlobalVariables("FileDateModified").Value = d; var dt = new Date(); var t_date = dt.getDate(); // Returns the day of the month var t_mon = dt.getMonth(); // Returns the month as a digit var t_year = dt.getFullYear(); // Returns 4 digit year //if (DateDiff(dt.getDate(), d.getDate()) < 7) if (DateDiff("d", dt, d) <= 7) { return(DTSTaskExecResult_Success); } }} |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-05 : 04:38:36
|
Not sure whether datadiff can be used in JavaScriptTry this alsoif (dt-d) >= 7){return(DTSTaskExecResult_Success); } MadhivananFailing to plan is Planning to fail |
 |
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-05 : 04:48:47
|
No, it gives a syntax error.Thanks |
 |
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-05 : 05:48:17
|
I think I worked it out.//**********************************************************************// Java ActiveX Script//************************************************************************function Main(){ var filespec = DTSGlobalVariables("FTPROOT").value + "\\" + DTSGlobalVariables("FILE").Value; var f; var d; var fso = new ActiveXObject("Scripting.FileSystemObject"); if ( fso.FileExists(filespec) == true); { f = fso.GetFile(filespec); d = f.DateLastModified; DTSGlobalVariables("FileDateModified").Value = d; var dt = new Date(); /* var t_date = dt.getDate(); // Returns the day of the month var t_mon = dt.getMonth(); // Returns the month as a digit var t_year = dt.getFullYear(); // Returns 4 digit year */ var difference = dt - d//unit is milliseconds var formatdifference=Math.round(difference/1000/60/60/24) //now unit is days if (formatdifference <= 7) //if the file is older than one week... { return(DTSTaskExecResult_Success); } else { return(DTSTaskExecResult_Failure) } }} |
 |
|
|