How to take current date, and put on an Insert?

Asked

Viewed 5,988 times

3

How can I get the current server date and put it in my query to send to the database? I have no idea how I can take the current time and put in a variable to send to the bank, thank you.

  • 1

    You can do this in the database language. If it is Mysql you can use NOW(). Have you tested this? In PHP there are several ways, one of them date("Y-m-d H:i:s")

  • NOW() takes date and time? I have not tested

  • Exact, like YYYY-MM-DD HH:MM:DD

  • Fatal error: Call to Undefined Function NOW() PATH

1 answer

4


You can do that in bank language.
If it’s Mysql you can use NOW() that gives YYYY-MM-DD HH:MM:DD date and time.

In PHP there are several ways, one of them date("Y-m-d H:i:s"), another is

$now = new DateTime();
$datetime = $now->format('Y-m-d H:i:s'); 
  • Fatal error: Call to Undefined Function NOW() in WAY

  • When I use NOW on Insert

  • 3

    @Evertonfigueiredo You got confused :) ... NOW not a PHP function is a mysql function, ie it should be a string in PHP within the query and not a function call, something like "INSERT INTO soFoo (first,last,minhadata) VALUES (0,1,Now())"

  • 1

    Thanks I was putting in the wrong place anyway.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.