Hello everyone, tell me in the cell there is such a value:

1356364843 

This is a Unix-Date, and so I need to turn it into a view:

 24.12.2012 

Because I need to make a comparison right away in the request, and if the date is equal to the one that the user indicates ... however, I don’t know how to immediately convert it to this view ... The request is like this:

 SELECT COUNT(id) FROM tb_user WHERE конвертация(date_reg) = '$date_enter' 

Where the conversion is the name of the function with which you can do this (I do not know what it is called), where $ date_enter is a variable in which the data entered by the user is stored.

  • four
    those. Do you suggest that the database server take each row of the table and convert the value from one field to a specific type and compare it with the value that you are too lazy to convert to the format stored in the database? think about the question again, maybe the solution will come by itself ... Shl just do not need to tell that there are only two entries in the TB_user table, later such queries are transferred to tables with millions of rows and the brakes are surprised by the Mayesquel. - Yura Ivanov
  • And which query is better then? - Csharp
  • one
    I think @Yura Ivanov? subtly hints to you that it is easier to convert the date you are going to use in the TIMESTAMP request condition)) - Deonis
  • Do not forget to compare the range with this conversion. those. date_reg <$ formated_date_input <date_reg + sec_per_day - Vladimir Klykov

1 answer 1

For MySQL it is done like this.

 SELECT COUNT(id) FROM tb_user WHERE date_reg = UNIX_TIMESTAMP('$date_enter') 

Note that it is not the value that is converted to the database, but the input parameter. This is much more efficient in terms of performance, because conversion needs to be performed only once, and not for each entry in the table. In addition, if the date_reg field date_reg indexed, then in this version the index will also be used