0

I am trying to use following queries but the browser says Fatal error: Call to undefined function FROM_UNIXTIME()

$query = "UPDATE table
             SET datetimefield = FROM_UNIXTIME($phpdate)
           WHERE...";
$query = "SELECT UNIX_TIMESTAMP(datetimefield)
            FROM table 
           WHERE...";

I am following http://www.richardlord.net/blog/dates-in-php-and-mysql

2
  • you can try if this works SELECT FROM_UNIXTIME((UNIX_TIMESTAMP(NOW()))) AS test Commented May 25, 2011 at 4:37
  • are you sure your database supports that function? what flavor and version of SQL do you have? Commented May 25, 2011 at 4:39

1 Answer 1

3

You cannot use a database function on a PHP variable. Try this:

$query = "UPDATE table
             SET datetimefield = FROM_UNIXTIME(" . strtotime($phpdate) . ")
           WHERE...";
$query = "SELECT UNIX_TIMESTAMP(datetimefield)
            FROM table 
           WHERE...";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.