Doubt mysql query + php

Asked

Viewed 30 times

0

I generate a date in PHP and saved in the database:

$today = date('Y-m-d H:i:s');
$timestamp = strtotime($today);

In the bank she is saved in this format: 1474496101

When I make a SELECT in this field using the query below for example, DO NOT RETURN ANYTHING.

SELECT * FROM teste.data WHERE data = FROM_UNIXTIME(1474496101) 

someone can tell me why ?

  • And how the column is defined data in the database?

  • sorry I had to edit pq missing a sentence. the date field is int type

  • The table name is teste.data even?

  • bank calls test and the date table and the date field

  • 2

    Right. What if the kind of data is int, why compare the value of the column with the return of FROM_UNIXTIME? Shouldn’t be data = 1474496101?

  • Friend you can pick up the current date directly by the bank. Use the now function()

  • I think you’re right, to use the FROM_UNIXTIME field type should be TIMESTAMP, correct? it was innocence at the time of creating the bank.

  • I want to use the graph to make the graph and it only accepts the query with FROM_UNIXTIME..

  • does not work I changed the field to TIMESTAMP it went to format 0000-00-00 00:00:00

Show 4 more comments

1 answer

1

discovered!

in the database can not be unixtime format has to be timestamp format for example: 0000-00-00 00:00:00.

I took the test now and it worked. Anyway thanks Anderson, your comments led me to the solution.

Browser other questions tagged

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