-2

I am trying to get the days between 2 dates, but I am only getting errors. I tried searching it but non of the things really helped me, I am hoping you guys can help a boy out right here.

The error I get with this code:

Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1582 Incorrect parameter count in the call to native function 'DATEDIFF' in C:\xampp\htdocs\Rent-a-Car\pages\medewerkers.php:197 Stack trace: #0 C:\xampp\htdocs\Rent-a-Car\pages\medewerkers.php(197): PDO->query('SELECT DATEDIFF...') #1 {main} thrown in C:\xampp\htdocs\Rent-a-Car\pages\medewerkers.php on line 197

my code to display it several times in the table

The database

The sql command that is used:

$sql1 = "SELECT * FROM factuur 
LEFT JOIN factuurregel ON factuur.Factuurnummer = factuurregel.Factuurnummer
LEFT JOIN gebruiker ON factuur.Klantcode = gebruiker.Klantcode
LEFT JOIN auto ON factuur.Kenteken = auto.Kenteken";
$sql2 = "SELECT DATEDIFF (day, Begindatum, Einddatum) AS Tijd from factuurregel;";
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 2
    Your error is pretty clear: You have an incorrect number of parameters inside of the DATEDIFF function. Read this for more information: https://stackoverflow.com/questions/28087748/get-date-difference – GasKa Jan 21 '19 at 13:33
  • 2
    (1) Tag your question with the database you are using. (2) Provide sample data and desired results. (3) Limit your question to a single query that generates the error. – Gordon Linoff Jan 21 '19 at 13:36
  • 1
    Possible duplicate of [Incorrect parameter count in the call to native function 'DATEDIFF'](https://stackoverflow.com/questions/23250555/incorrect-parameter-count-in-the-call-to-native-function-datediff) – devpro Jan 21 '19 at 13:36

3 Answers3

1

DATADIFF function returns a number of days between two dates. You shouldn't pass day parameter in it

SELECT DATEDIFF (Begindatum, Einddatum) AS Tijd FROM factuurregel
Maksym Fedorov
  • 6,383
  • 2
  • 11
  • 31
1

the error says that count of parameters is invalid. according to the docs - https://www.w3resource.com/mysql/date-and-time-functions/mysql-datediff-function.php:

SELECT DATEDIFF (Begindatum, Einddatum) AS Tijd from factuurregel
myxaxa
  • 1,391
  • 1
  • 8
  • 7
  • This will still give me this error: object(PDOStatement)#5 (1) { ["queryString"]=> string(66) "SELECT DATEDIFF (Begindatum, Einddatum) AS Tijd from factuurregel;" } – thisishowithastobedone Jan 21 '19 at 13:37
0

If you are using MySQL, then presumably you want:

SELECT DATEDIFF(Einddatum, Begindatum) AS Tijd
FROM factuurregel;

Note that the arguments are reversed. Both MySQL and SQL Server have functions called datediff(). They differ not only in the number of arguments but also in the order of the dates.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786