NOW() function in PHP
You can use the date function:
date("Y-m-d H:i:s");
How use the function NOW() in PHP
now is not php function so replace
NOW()
to
date('Y-m-d H:i:s')
so your final code
$correspondent = new CorrespondentBis($data['id'], $data['code_client'], $data['name'], $data['surname'], $data['phone'], $data['fax'], $data['email'], get_current_user(), date('Y-m-d H:i:s'), 0);
2.no need to use quote , just use NOW()
so your final query
$sql = "INSERT INTO `...`.`correspondants_bis`
(`code_client` , `name`, `surname` ,`phone`, `fax`, `email`, `added_by`, `Date`, `condition`)
VALUES ('" . $correspondent->getCodeClient() . "',
'" . str_replace("'", "''", $correspondent->getName()) . "',
'" . str_replace("'", "''", $correspondent->getSurname()) . "',
'" . $correspondent->getPhone() . "',
'" . $correspondent->getFax() . "',
'" . $correspondent->getEmail() . "',
'" . $user . "',
NOW(),
'1'
);";
for more information
http://www.mysqltutorial.org/mysql-now/
Now' Function query in php to get current date and time
No Need to execute query if you want to get current date and time in PHP. Check below date function
<?php echo date('d-M-Y H:i:s'); ?>
Date('now') in PHP
"now" is not a valid parameter for for this expectation, infact it should be strtotime function here, not date.
Date considers your now as
n
Numeric representation of a month, without leading zeros
o
ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)
w
Numeric representation of the day of the week
binding parameters using the NOW function
NOW()
is not a parameter of a query. Just put it like this:
$stmt = $conn->prepare("INSERT INTO MyGuests (firstname, lastname, date) VALUES (?, ?, NOW())");
$stmt->bind_param("sss", $firstname, $lastname);
Uncaught Error: Call to undefined function NOW()
Use $date = date();
, NOW()
is for MySQL.
Read the documentation for more information about date()
.
Here is an example (from this documentation) :
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // It is the 10th day (10ème jour du mois).
$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \e\s\t\ \l\e\ \m\o\i\s'); // 17:03:18 m est le mois
$today = date("H:i:s"); // 17:16:18
$today = date("Y-m-d H:i:s"); // 2001-03-10 17:16:18 (le format DATETIME de MySQL)
To get the current date in datetime
format, you can do :
$date = new Datetime();
Read the documentation for more information about datetime
.
If you are in MySQL, you can use NOW()
like this for example :
$sql = "INSERT INTO mytable (current_date) VALUE (NOW())";
And again, here is the documentation if you want to know more about NOW()
.
Hope it helps !
Related Topics
Pass Arraylist Bean from Android to Webservice PHP
How to Prevent Multiple Logins in PHP Website
When *Not* to Use Prepared Statements
Apache Error [Notice] Parent: Child Process Exited with Status 3221225477 -- Restarting
PHP + SQL Server - How to Set Charset for Connection
Getting Pear to Work on Xampp (Apache/MySQL Stack on Windows)
Is MySQL_Real_Escape_String() Necessary When Using Prepared Statements
PHP Error: Function Name Must Be a String
Target Class Does Not Exist. Problem in Laravel 8
Decode a Quoted Printable Message in PHP
PHP Is Not Recognized as an Internal or External Command in Command Prompt
Android JSON Httpclient to Send Data to PHP Server with Httpresponse
What Security Issues Should I Look Out for in PHP
Process CSV into Array with Column Headings for Key
How to Call a Controller Function Inside a View in Laravel 5