DateAdd Too few parameters. Expected 1 (1 Viewer)

jxwd

Member
Local time
Today, 12:10
Joined
Apr 6, 2022
Messages
35
I wish! :) it's not practice as the company has many inhouse systems still using access... the only sticking issues is this one! and as the article suggests is should work... !
 

cheekybuddha

AWF VIP
Local time
Today, 12:10
Joined
Jul 21, 2014
Messages
2,321
PHP:
///////////////////////////////////////////////////////////////////////////////////
// db_query - this does global error handling... all subsiquent chould use this...
///////////////////////////////////////////////////////////////////////////////////
//
function db_query ($query, $error_message) {
  $result = odbc_exec($this->ms_access, $query);
  if (odbc_error($this->ms_access))
      die(odbc_errormsg($this->ms_access)."<br />".$query."<br />".$error_message);
  else
      return $result;
}

$sql = 'SELECT DateOfCal AS NextCal FROM TblCalibItems;';
$rs = db_query($sql, $err_msg);
while ($row = odbc_fetch_array($rs)) {
  $dt = new DateTime($row['NextCal']);
  $dt = $dt->add(new DateInterval('P3M');
  echo($dt->format('Y-m-d');
}
 
Last edited:

jxwd

Member
Local time
Today, 12:10
Joined
Apr 6, 2022
Messages
35
It needs to be sorted by the calculated result. So I will need to run ksort / asort after this... and TblCalibItems has a lot of records...

IE SELECT DateAdd(\"m\", NoOfMonths, DateValue(DateOfCal))

NoOfMonths is an integer variable...
 

jxwd

Member
Local time
Today, 12:10
Joined
Apr 6, 2022
Messages
35
No but, I am working toward NextCal as the sort order too IE

SELECT DateAdd(\"month\", NoOfMonths, DateOfCal) AS NextCal ORDER BY NextCal;

NoOfMonths could be 1 or 120...
 

jxwd

Member
Local time
Today, 12:10
Joined
Apr 6, 2022
Messages
35
And it definitely knows DateAdd as it doesn't complain that it's not defined... feels so near but so far! :)
 

jxwd

Member
Local time
Today, 12:10
Joined
Apr 6, 2022
Messages
35
Success this ran, I think 'm' not months, or mm and with the single quotes... :

SELECT TOP 10 *,DateAdd('m',-2,now()) AS NextCal FROM TblCalibItems;

Thank you all :)
 

Users who are viewing this thread

Top Bottom